forked from frederico4d/ActionLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionLoader_b279.py
836 lines (684 loc) · 32 KB
/
ActionLoader_b279.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
bl_info = {
"name": "Action Loader",
"author": "Frederico Martins",
"version": (1, 8),
"blender": (2, 78, 0),
"location": "View3D > Tools > Animation",
"description": "Lists all Actions and assigns it to active object",
"warning": "",
"wiki_url": "https://github.com/frederico4d/ActionLoader",
"tracker_url": "https://github.com/frederico4d/ActionLoader/issues",
"category": "Animation",
}
## TODO
### novas funcoes
## meter mais paineis duplicaveis em vez de so 2?
## meter o action loader nas properties ou em outro lado
#para se puder ver num painel separado, em outro ecra etc...
### optimizações
import bpy
def set_prevspeed(self, value):
global prev_mode
global old_prevspeed
old_prevspeed = bpy.context.scene.actionloader_speedprev
if bpy.context.scene.actionloader_speedprev == "0":
print ("ZERO")
prev_mode = bpy.context.scene.use_preview_range
self["testprop"] = value
def get_prevspeed(self):
#print("get")
return self["testprop"]
def update_prevspeed(self, context):
speed = bpy.context.scene.actionloader_speedprev
print("SPEEDCHANGE")
ob = bpy.context.scene.objects.active
#ob = context.object
scn = context.scene
ActiveAction = ob.animation_data.action
if scn.actionloader_rangemode == "0":
sframe = ActiveAction["frame_start"]
eframe = ActiveAction["frame_end"]
else:
sframe = ActiveAction.frame_range[0]
eframe = ActiveAction.frame_range[1]
print("OLD: ",old_prevspeed)
if speed == "0":
scn.frame_start = sframe
scn.frame_end = eframe
scn.render.frame_map_new = 100
if old_prevspeed == "1":
scn.frame_current = scn.frame_current / 2
elif old_prevspeed == "2":
scn.frame_current = scn.frame_current / 4
elif old_prevspeed == "3":
scn.frame_current = scn.frame_current / 8
scn.use_preview_range = prev_mode
elif speed == "1":
scn.frame_start = sframe*2
scn.frame_end = eframe*2
scn.render.frame_map_new = 200
if old_prevspeed == "0":
scn.frame_current = scn.frame_current * 2
elif old_prevspeed == "2":
scn.frame_current = scn.frame_current / 2
elif old_prevspeed == "3":
scn.frame_current = scn.frame_current / 4
scn.use_preview_range = False
elif speed == "2":
scn.frame_start = sframe*4
scn.frame_end = eframe*4
scn.render.frame_map_new = 400
if old_prevspeed == "0":
scn.frame_current = scn.frame_current * 4
elif old_prevspeed == "1":
scn.frame_current = scn.frame_current * 2
elif old_prevspeed == "3":
scn.frame_current = scn.frame_current / 2
scn.use_preview_range = False
elif speed == "3":
scn.frame_start = sframe*8
scn.frame_end = eframe*8
scn.render.frame_map_new = 800
if old_prevspeed == "0":
scn.frame_current = scn.frame_current * 8
elif old_prevspeed == "1":
scn.frame_current = scn.frame_current * 4
elif old_prevspeed == "2":
scn.frame_current = scn.frame_current * 2
scn.use_preview_range = False
def set_normal_speed():
scn = bpy.context.scene
if bpy.context.object == None or bpy.context.object.animation_data == None or bpy.context.object.animation_data.action == None:
pass
else:
ActiveAction = scn.objects.active.animation_data.action
if ActiveAction.get("frame_start") != None:
scn.frame_start = ActiveAction["frame_start"]
scn.frame_end = ActiveAction["frame_end"]
else:
scn.frame_start = ActiveAction.frame_range[0]
scn.frame_end = ActiveAction.frame_range[1]
scn.use_preview_range = prev_mode
scn.actionloader_speedprev = '0'
scn.render.frame_map_new = 100
def update_rangemode(self, context):
ob = bpy.context.scene.objects.active
ActiveAction = ob.animation_data.action
if context.scene.actionloader_rangemode == "0":
if ActiveAction.get("frame_start") == None:
pass
else:
context.scene.frame_preview_start = ActiveAction["frame_start"]
context.scene.frame_preview_end = ActiveAction["frame_end"]
context.scene.frame_start = ActiveAction["frame_start"]
context.scene.frame_end = ActiveAction["frame_end"]
elif context.scene.actionloader_rangemode == "1":
if ActiveAction == None:
pass
else:
context.scene.frame_preview_start = ActiveAction.frame_range[0]
context.scene.frame_preview_end = ActiveAction.frame_range[1]
context.scene.frame_start = ActiveAction.frame_range[0]
context.scene.frame_end = ActiveAction.frame_range[1]
def update_action_list_noObj(self, context):
pass
def save_action_extras():
scn = bpy.context.scene
ob = scn.objects.active
if ob:
ActiveAction = ob.animation_data.action
else:
ActiveAction = bpy.data.actions[scn.action_list_index]
ActiveAction.use_fake_user = True
## Assign start and end frame props to current action
if scn.actionloader_rangemode == "0" and scn.actionloader_autorange:
if scn.use_preview_range:
ActiveAction["frame_start"] = scn.frame_preview_start
ActiveAction["frame_end"] = scn.frame_preview_end
else:
ActiveAction["frame_start"] = scn.frame_start
ActiveAction["frame_end"] = scn.frame_end
#Saves current markers to action
if scn.actionloader_markers and ob:
save_markers_to_action()
def update_action_list(self, context):
#updates every time you pick action in the list
ob = bpy.context.scene.objects.active
#ob = context.object
scn = context.scene
if scn.render.frame_map_new != 100:
set_normal_speed()
if ob.animation_data == None:
action = 0 # No Animation data
elif ob.animation_data.action == None:
action = 1 # No Action
else:
action = 2 # Has Action
if action == 2: # Has action
save_action_extras()
elif action == 0: # No Animation data
ob.animation_data_create()
#then change the action to the picked on the list
ob.animation_data.action = bpy.data.actions[ob.action_list_index]
ActiveAction = context.scene.objects.active.animation_data.action
ActiveAction.use_fake_user = True
# Changes the range on the scene
if ActiveAction.get("frame_start") != None and scn.actionloader_autorange:
if context.scene.actionloader_rangemode == "0":
scn.frame_preview_start = ActiveAction["frame_start"]
scn.frame_preview_end = ActiveAction["frame_end"]
scn.frame_start = ActiveAction["frame_start"]
scn.frame_end = ActiveAction["frame_end"]
elif context.scene.actionloader_rangemode == "1":
scn.frame_preview_start = ActiveAction.frame_range[0]
scn.frame_preview_end = ActiveAction.frame_range[1]
scn.frame_start = ActiveAction.frame_range[0]
scn.frame_end = ActiveAction.frame_range[1]
#center stuff on dopesheet etc...
for area in context.screen.areas:
if area.type == 'DOPESHEET_EDITOR':
for region in area.regions:
if region.type == 'WINDOW':
override = {'area': area, 'region': region, 'edit_object': context.edit_object}
bpy.ops.action.view_all(override)
elif area.type == 'GRAPH_EDITOR':
for region in area.regions:
if region.type == 'WINDOW':
override = {'area': area, 'region': region, 'edit_object': context.edit_object}
bpy.ops.graph.view_all(override)
elif area.type == 'TIMELINE':
for region in area.regions:
if region.type == 'WINDOW':
override = {'area': area, 'region': region, 'edit_object': context.edit_object}
bpy.ops.time.view_all(override)
if scn.actionloader_markers == True:
change_timelinemarkers_from_action()
class ACTION_UL_list2(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
self.use_filter_show = True
ob = bpy.context.scene.objects.active
#ob = bpy.context.object
if self.layout_type in {'DEFAULT', 'COMPACT'}:
if bpy.context.scene.actionloader_showicons:
layout.prop(item, "name", text="", emboss=False, icon_value=icon)
else:
layout.prop(item, "name", text="", emboss=False)
#layout.operator("delete.action", text="", icon = "ERROR").delaction = bpy.data.actions[ob.action_list_index].name
#layout.operator("ttt.action", text ="T").nome = str(self._DATA)
#layout.label(text = "", icon = "ERROR")
elif self.layout_type in {'GRID'}:
pass
global filter_name2
filter_name2 = self.filter_name
class ACTION_UL_list(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
self.use_filter_show = True
if item.use_fake_user == True:
fakeuser = "F"
else:
fakeuser = "X"
info = str(item.users)+ fakeuser + " " + str(len(item.pose_markers)) + "M"
if self.layout_type in {'DEFAULT', 'COMPACT'}:
if bpy.context.scene.actionloader_showicons:
layout.prop(item, "name", text="", emboss=False, icon_value=icon)
else:
layout.prop(item, "name", text="", emboss=False)
#layout.operator("delete.action", text="", icon = "ERROR").delaction = bpy.data.actions[ob.action_list_index].name
#layout.operator("ttt.action", text ="T").nome = str(self._DATA)
#layout.label(text = info)
elif self.layout_type in {'GRID'}:
pass
global filter_name
filter_name = self.filter_name
class UIListPanelExample(bpy.types.Panel):
"""Creates a Panel in the Animation tab of the 3D View's Tools"""
bl_label = "Action Loader"
bl_idname = "OBJECT_PT_ui_list_example"
"""
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
"""
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_category = "Animation"
def draw(self, context):
layout = self.layout
scn = context.scene
ob = scn.objects.active
#ob = context.object
animation = True
if context.scene.objects.active != None:
# Sets icon depending on what is selected and the current mode.
if context.mode == "OBJECT":
object_icon = "OUTLINER_OB_"+ str(ob.type)
elif context.mode == "POSE":
object_icon = "POSE_HLT"
else:
object_icon = str(ob.type) + "_DATA"
row = layout.row(align = True)
row.label (text = ob.name, icon = object_icon)
if ob.animation_data and ob.animation_data.action:
if ob.animation_data.action.fcurves.find('location', index=0):
if ob.animation_data.action.fcurves.find('location', index=0).mute == False:
mute_ico = "MUTE_IPO_OFF"
else:
mute_ico = "MUTE_IPO_ON"
row.operator("muteloc.action", icon = mute_ico)
row.operator ("unselect.object", icon = "X")
info2 = "-f. | -s."
if ob.animation_data == None or ob.animation_data.action == None:
info2 = "--f. | -s."
if ob.animation_data == None:
layout.label (text = "NO 'animation_data'")
elif ob.animation_data.action == None:
layout.label (text = "NO 'action'")
layout.label(text = "Tip: Insert Keyframe" , icon = "INFO")
elif ob.animation_data.action:
if ob.action_list_index > (len(bpy.data.actions)-1):
action_icon = "ERROR"
elif bpy.data.actions[ob.action_list_index] != ob.animation_data.action:
# When the active object's action is different than the one listed on the index
print("DISTINTODIFERENTE")
action_icon = "ERROR"
else:
action_icon = "ACTION"
AA = ob.animation_data.action ##ActiveAction
row = layout.row(align=True)
row.label (text = AA.name, icon = action_icon)
if action_icon == "ERROR":
row.operator("fix.action", icon = "FILE_TICK")
else:
row.operator("duplicate.action", icon = "ZOOMIN")
row.operator("unlinks.action", icon = "X")
if AA.use_fake_user:
fakeuser= " [F]"
else:
fakeuser= " [x]"
if AA.get("frame_end") == None:
durationf = 0
durations = 0
else:
durationf = AA["frame_end"] - AA["frame_start"]
durations = durationf / bpy.context.scene.render.fps
info1 = AA.name
info2 = str(durationf)+ " f. | "+ str(round(durations,6))+ " s. "
# Draw Info!
row = layout.row(align=True)
row.label(text = str(AA.users)+"Users "+fakeuser + " | " + str(len(AA.pose_markers))+"Markers", icon = "INFO")
row.operator("renderprev.action", icon = "RENDER_ANIMATION")
if context.scene.actionloader_rangemode == '1':
rangemode_icon = "SPACE2"
else:
rangemode_icon = "SPACE3"
row = layout.row(align=True)
row.label (text = info2, icon = "PREVIEW_RANGE")
row.label(icon = rangemode_icon)
list_context = ob
elif context.scene.objects.active == None and len(bpy.data.actions) >=1:
ListedAction = bpy.data.actions[bpy.context.scene.action_list_index]
layout.label(text = "Tip: Select an Object", icon = "INFO")
row = layout.row(align=True)
row.label (text = ListedAction.name, icon = "ACTION")
row.operator("duplicate.action", icon = "ZOOMIN")
if ListedAction.use_fake_user:
fakeuser= " [F]"
else:
fakeuser= " [x]"
if ListedAction.get("frame_end") == None:
durationf = 0
durations = 0
else:
durationf = ListedAction["frame_end"] - ListedAction["frame_start"]
# Draw Info!
layout.label(text = str(ListedAction.users)+"Users "+fakeuser + " | " + str(len(ListedAction.pose_markers))+"Markers", icon = "INFO")
durations = durationf / bpy.context.scene.render.fps
info2 = str(durationf)+ " f. | "+ str(round(durations,6))+ " s. "
if context.scene.actionloader_rangemode == '1':
rangemode_icon = "SPACE2"
else:
rangemode_icon = "SPACE3"
row = layout.row(align=True)
row.label (text = info2, icon = "PREVIEW_RANGE")
row.label(icon = rangemode_icon)
list_context = scn
else:
layout.label (text= "Just start animating!", icon = "INFO")
list_context = scn
#UIList - no object
row = layout.row(align=True)
row.template_list("ACTION_UL_list", "", bpy.data, "actions", list_context, "action_list_index")
if bpy.context.scene.actionloader_DualView:
row.template_list("ACTION_UL_list2", "", bpy.data, "actions", list_context, "action_list_index")
## First View!!!!!!!!!!!!!!!!!!!1
action_names= []
for x in range (len(bpy.data.actions)):
action_names.append(bpy.data.actions[x].name.lower())
filtered_actions = [k for k in action_names if filter_name.lower() in k]
total_anims=len(bpy.data.actions.items())
listed_anims =len(filtered_actions)
row = layout.row(align=True)
if filter_name == "":
row.label(text = str(total_anims) +" anims total", icon = "INFO")
else:
row.label(text = str(listed_anims)+ " of " +str(total_anims) +" anims", icon = "INFO")
## DualView!!!!!!!!!!!!!!!!!!!!2
if bpy.context.scene.actionloader_DualView:
action_names= []
for x in range (len(bpy.data.actions)):
action_names.append(bpy.data.actions[x].name.lower())
filtered_actions = [k for k in action_names if filter_name2.lower() in k]
total_anims=len(bpy.data.actions.items())
listed_anims =len(filtered_actions)
if filter_name2 == "":
row.label(text = str(total_anims) +" anims total", icon = "INFO")
else:
row.label(text = str(listed_anims)+ " of " +str(total_anims) +" anims", icon = "INFO")
# DUAL VIEW ICON BT
if scn.actionloader_DualView:
dual_icon = "GO_LEFT"
else:
dual_icon = "SPLITSCREEN"
row.prop(scn, 'actionloader_DualView', text = "", icon = dual_icon)
#Icons for Rangemode
if context.scene.actionloader_rangemode == '1':
rangemode_icon = "SPACE2"
else:
rangemode_icon = "SPACE3"
layout.label(text = "Prev Speed:")
layout.prop(context.scene, 'actionloader_speedprev', expand=True)
layout.label(text = "Set Frame Range:")
row = layout.row(align=True)
row.prop(context.scene, 'actionloader_rangemode', expand=True )
row.label(icon = rangemode_icon)
layout.operator("setcustombyrange.action", icon = "FILE_REFRESH")
#layout.operator("ttt.action", text ="TTTTTT###TTTTTTTT").nome = "conho"
layout.label (text = "Other Tools: ")
layout.operator("delete.action", icon = "ERROR")
#.delaction = bpy.data.actions[ob.action_list_index].name
#layout.label (text = "Render Preview:")
#layout.operator("renderprev.action",text = "Render Preview", icon = "RENDER_ANIMATION")
layout.label(text= "Options:")
layout.prop(scn, 'actionloader_DualView', text = "Dual View")
layout.prop(scn, "actionloader_showicons", text="Show Icons")
layout.prop(scn, "actionloader_autorange", text="Set Auto Range")
layout.prop(scn, "actionloader_markers", text="Use Action Markers")
class OBJECT_OT_SetActionRange(bpy.types.Operator):
"""Sets current timeline range to action"""
bl_idname = "set.actionrange"
bl_label = "Set Action range by timeline"
def execute(self, context):
scn = context.scene
ActiveAction = scn.objects.active.animation_data.action
print(ActiveAction)
ActiveAction.use_fake_user = True
if bpy.context.scene.use_preview_range:
ActiveAction["frame_start"] = scn.frame_preview_start
ActiveAction["frame_end"] = scn.frame_preview_end
else:
ActiveAction["frame_start"] = scn.frame_start
ActiveAction["frame_end"] = scn.frame_end
return{'FINISHED'}
class OBJECT_OT_UnselectObject(bpy.types.Operator):
"""Makes Object not active, but you can keep editing the action list"""
bl_idname = "unselect.object"
bl_label = ""
def execute(self, context):
if context.scene.action_list_index < 0 :
context.scene.action_list_index = 0
context.scene.objects.active = None
return{'FINISHED'}
class OBJECT_OT_DuplicateAction(bpy.types.Operator):
"""Duplicate Action"""
bl_idname = "duplicate.action"
bl_label = ""
def execute(self, context):
scn = bpy.context.scene
ob = scn.objects.active
save_action_extras()
"""
#Saves current markers to action
if bpy.context.scene.actionloader_markers:
save_markers_to_action()
### Saves extra stuff on current action
ActiveAction = scn.objects.active.animation_data.action
ActiveAction.use_fake_user = True
## Assign start and end frame props to current action
if scn.actionloader_rangemode == "0" and scn.actionloader_autorange:
if scn.use_preview_range:
print("bb")
ActiveAction["frame_start"] = scn.frame_preview_start
ActiveAction["frame_end"] = scn.frame_preview_end
else:
print("cc")
ActiveAction["frame_start"] = scn.frame_start
ActiveAction["frame_end"] = scn.frame_end
"""
if ob == None:
newAnim = bpy.data.actions[scn.action_list_index].copy()
else:
newAnim = bpy.data.actions[bpy.context.object.action_list_index].copy()
ob.animation_data.action = newAnim
quickfix_index()
return{'FINISHED'}
class OBJECT_OT_UnlinkAction(bpy.types.Operator):
"""Unlinks Action from Active Object"""
bl_idname = "unlinks.action"
bl_label = ""
def execute(self, context):
ob = bpy.context.scene.objects.active
save_action_extras()
ob.animation_data.action = None
return{'FINISHED'}
class OBJECT_OT_fixsync(bpy.types.Operator):
"""Quick fix for unmaching action in Action Loader list"""
bl_idname = "fix.action"
bl_label = "fix"
def execute(self, context):
quickfix_index()
return{'FINISHED'}
class OBJECT_OT_speedup(bpy.types.Operator):
"""Toggles between, 1/2x - 1/4x - 1/8x and Normal speeds for preview only - uses the 'Time Remapping' values"""
bl_idname = "speeddown.action"
bl_label = ""
def execute(self, context):
ob = bpy.context.scene.objects.active
#ob = context.object
ActiveAction = ob.animation_data.action
global prev_mode
if ob == None or ob.animation_data == None or ActiveAction == None:
bpy.context.scene.render.frame_map_new = 100
else:
if context.scene.actionloader_rangemode == "0":
sframe = ActiveAction["frame_start"]
eframe = ActiveAction["frame_end"]
else:
sframe = ActiveAction.frame_range[0]
eframe = ActiveAction.frame_range[1]
if context.scene.render.frame_map_new == 100:
context.scene.frame_start = sframe*2
context.scene.frame_end = eframe*2
context.scene.render.frame_map_new = 200
context.scene.frame_current = context.scene.frame_current*2
prev_mode = bpy.context.scene.use_preview_range
context.scene.use_preview_range = False
elif context.scene.render.frame_map_new == 200:
context.scene.frame_start = sframe*4
context.scene.frame_end = eframe*4
context.scene.render.frame_map_new = 400
context.scene.frame_current = context.scene.frame_current*2
context.scene.use_preview_range = False
elif context.scene.render.frame_map_new == 400:
context.scene.frame_start = sframe*8
context.scene.frame_end = eframe*8
context.scene.render.frame_map_new = 800
context.scene.frame_current = context.scene.frame_current*2
context.scene.use_preview_range = False
else:
bpy.context.scene.use_preview_range = prev_mode
set_normal_speed()
return{'FINISHED'}
class OBJECT_OT_customByRange(bpy.types.Operator):
"""Sets the custom range by the action's frame_range (first and last keyframes)"""
bl_idname = "setcustombyrange.action"
bl_label = "Set Frame Range"
def execute(self, context):
ob = bpy.context.scene.objects.active
ActiveAction = ob.animation_data.action
ActiveAction["frame_start"] = ActiveAction.frame_range[0]
ActiveAction["frame_end"] = ActiveAction.frame_range[1]
update_rangemode(self, bpy.context)
return{'FINISHED'}
class OBJECT_OT_renderprev(bpy.types.Operator):
"""Render Preview with Action Name (set output path to end in "/", without filename)"""
bl_idname = "renderprev.action"
bl_label = ""
def execute(self, context):
scn = bpy.context.scene
cam = scn.render.filepath
if scn.render.image_settings.file_format == 'THEORA'and scn.render.use_file_extension == False:
ext = ".ogv"
else:
ext = ""
scn.render.filepath = cam + bpy.context.object.animation_data.action.name + ext
if bpy.context.space_data.show_only_render == False:
bpy.context.space_data.show_only_render = True
bpy.ops.render.opengl(animation=True)
bpy.context.space_data.show_only_render = False
else:
bpy.ops.render.opengl(animation=True)
scn.render.filepath = cam
return{'FINISHED'}
class OBJECT_OT_muter(bpy.types.Operator):
"""Mutes Location"""
bl_idname = "muteloc.action"
bl_label = ""
def execute(self, context):
ob = bpy.context.scene.objects.active
AA = ob.animation_data.action
mute_to = False
if AA.fcurves.find('location', index=0).mute == False:
mute_to = True
# Mutes Location
AA.fcurves.find('location', index=0).mute = mute_to
AA.fcurves.find('location', index=1).mute = mute_to
AA.fcurves.find('location', index=2).mute = mute_to
# Hides Location
AA.fcurves.find('location', index=0).hide = mute_to
AA.fcurves.find('location', index=1).hide = mute_to
AA.fcurves.find('location', index=2).hide = mute_to
# Locks Location
AA.fcurves.find('location', index=0).lock = mute_to
AA.fcurves.find('location', index=1).lock = mute_to
AA.fcurves.find('location', index=2).lock = mute_to
return{'FINISHED'}
class OBJECT_OT_ttt(bpy.types.Operator):
"""TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"""
bl_idname = "ttt.action"
bl_label = ""
nome = bpy.props.StringProperty()
def execute(self, context):
print (self.nome)
return{'FINISHED'}
class OBJECT_OT_DeleteAction(bpy.types.Operator):
""" WARNING: Deletes Action from Blender File"""
bl_idname = "delete.action"
bl_label = "Delete Action"
#delaction = bpy.props.StringProperty()
def execute(self, context):
#set_normal_speed()
ob = bpy.context.scene.objects.active
if ob == None:
ActionNR = context.scene.action_list_index
else:
ActionNR = context.object.action_list_index
AA = bpy.data.actions[ActionNR]
if ob:
ob.action_list_index = bpy.context.object.action_list_index-1
else:
bpy.context.scene.action_list_index = bpy.context.scene.action_list_index-1
bpy.data.actions.remove(AA, True)
#bpy.data.actions.remove(bpy.data.actions[self.delaction], True)
return{'FINISHED'}
def change_timelinemarkers_from_action():
ob = bpy.context.object
scn = bpy.context.scene
# remove markers from timeline
for ai in range(len(scn.timeline_markers)):
scn.timeline_markers.remove(scn.timeline_markers[0])
#adds action markers to timeline
for bi in range(len(ob.animation_data.action.pose_markers)):
scn.timeline_markers.new(ob.animation_data.action.pose_markers[bi].name, ob.animation_data.action.pose_markers[bi].frame)
def save_markers_to_action():
ob = bpy.context.scene.objects.active
AA = ob.animation_data.action
#delete pose markers from the action
for i in range(len(AA.pose_markers)):
AA.pose_markers.remove(AA.pose_markers[0])
# assign pose markers from timeline markers
for i in range(len(bpy.context.scene.timeline_markers)):
AA.pose_markers.new(bpy.context.scene.timeline_markers[i].name)
AA.pose_markers[i].frame = bpy.context.scene.timeline_markers[i].frame
def quickfix_index():
for x in range(len(bpy.data.actions)):
if bpy.data.actions[x] == bpy.context.object.animation_data.action:
if bpy.context.scene.actionloader_markers == True:
change_timelinemarkers_from_action()
bpy.context.object.action_list_index = x
def register():
bpy.types.Scene.actionloader_DualView = bpy.props.BoolProperty(default= False)
bpy.types.Object.action_list_index = bpy.props.IntProperty(
update = update_action_list,
description = "Action Loader's highlighted action on list for this object"
)
bpy.types.Scene.action_list_index = bpy.props.IntProperty(
update = update_action_list_noObj,
description = "Action Loader's highlighted action on list for this scene when no object selected"
)
enum_items = (
('0','Custom','Sets Frame Range of action by the current Frame Range'),
('1','Keyframes',"Sets Frame Range by action's first and last keyframe")
)
bpy.types.Scene.actionloader_rangemode = bpy.props.EnumProperty(
items = enum_items,
update = update_rangemode,
description = "Set the ranfe for 0: custom or 1: based on keyframes"
)
enum_prevspeed = (
('0','Normal','Set speed to Normal (Time Remapping "frame_map_new" to 100 and adjusts range)'),
('1','1/2', 'Set speed to half (Time Remapping "frame_map_new" to 200 and adjusts range)'),
('2','1/4', 'Set speed to a quarter (Time Remapping "frame_map_new" to 400 and adjusts range)'),
('3','1/8', 'Set speed to an eighth (Time Remapping "frame_map_new" to 800 and adjusts range)')
)
bpy.types.Scene.actionloader_speedprev = bpy.props.EnumProperty(
items = enum_prevspeed,
update=update_prevspeed,
set = set_prevspeed,
get = get_prevspeed
)
bpy.types.Scene.actionloader_showicons = bpy.props.BoolProperty(
name = "Show icons",
description = "Show icons in Action Loader Addon",
default = True
)
bpy.types.Scene.actionloader_autorange = bpy.props.BoolProperty(
name = "Set Auto Range",
description = "Automatically set and load Frame Ranges for each Action and zoom in on Loading actions",
default = True
)
bpy.types.Scene.actionloader_markers = bpy.props.BoolProperty(
name = "Set Action Markers",
description = "Automatically assign pose_markers from action to scene timeline_markers (kind of uses scene Markers as Local Markers)",
default = True
)
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Object.action_list_index
del bpy.types.Scene.action_list_index
del bpy.types.Scene.actionloader_showicons
del bpy.types.Scene.actionloader_autorange
del bpy.types.Scene.actionloader_markers
del bpy.types.Scene.actionloader_speedprev
if __name__ == "__main__":
register()