-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmvbh_operators.py
887 lines (730 loc) · 31.6 KB
/
mvbh_operators.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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
# MeshVoid's Bone Helper addon operators
import bpy
from .mvbh_methods import MVBH_Scripts
from .mvbh_info import MVBH_Messages
# TODO: DEFINE ALL OPERATORS TO BE USED IN ADDON
class MVBH_Operator():
def __init__(self):
self.script = MVBH_Scripts()
self.info = MVBH_Messages()
global replaced_bone_name
self.replaced_bone_name = ""
def check_errors(self):
if bpy.context.mode == "EDIT_ARMATURE":
if not bool(bpy.context.selected_bones):
self.info.display_err(2)
self.report({"ERROR"}, self.info.errors[2])
return {"CANCELLED"}
if bpy.context.mode == "EDIT_ARMATURE":
if not bool(bpy.context.selected_bones):
self.info.display_err(0)
self.report({"ERROR"}, self.info.errors[0])
return {"CANCELLED"}
if bpy.context.mode == "POSE":
if not bool(bpy.context.selected_pose_bones):
self.info.display_err(0)
self.report({"ERROR"}, self.info.errors[0])
return {"CANCELLED"}
class MVBH_OT_main_menu(bpy.types.Operator):
bl_idname = "mvbh.main_menu"
bl_label = "MeshVoid Bone Helper Menu"
bl_description = "Show's MeshVoid Bone Helped addon Main Menu"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bpy.ops.wm.call_menu(name="VIEW3D_MT_MVBH_Main_Menu")
return {"FINISHED"}
class MVBH_OT_set_def_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_def_bones"
bl_label = "Set Deform bones"
bl_description = "Set Deform bone properties to selected bones"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(
prefix=self.script.def_prefix, deform=True)
self.script.move_selected_bones_to_layer(
layer_number=self.script.def_layer,
layer_name=self.script.def_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(2)
self.report({"OPERATOR"}, self.info.messages[2])
return {"FINISHED"}
class MVBH_OT_set_tgt_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_tgt_bones"
bl_label = "Set Target bones"
bl_description = "Set Target bone properties to selected bones"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(
prefix=self.script.tgt_prefix)
self.script.move_selected_bones_to_layer(
layer_number=self.script.tgt_layer,
layer_name=self.script.tgt_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(3)
self.report({"OPERATOR"}, self.info.messages[3])
return {"FINISHED"}
class MVBH_OT_set_ctl_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_ctl_bones"
bl_label = "Set Control bones"
bl_description = "Set Control bone properties to selected bones"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(prefix=self.script.ctl_prefix)
self.script.move_selected_bones_to_layer(
layer_number=self.script.ctl_layer,
layer_name=self.script.ctl_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(4)
self.report({"OPERATOR"}, self.info.messages[4])
return {"FINISHED"}
class MVBH_OT_set_mch_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_mch_bones"
bl_label = "Set Mechanism bones"
bl_description = "Set Mechanism bone properties to selected bones"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(prefix=self.script.mch_prefix)
self.script.move_selected_bones_to_layer(
layer_number=self.script.mch_layer,
layer_name=self.script.mch_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(5)
self.report({"OPERATOR"}, self.info.messages[5])
return {"FINISHED"}
class MVBH_OT_set_left_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_left_suffix"
bl_label = "Set Left side suffix"
bl_description = "Set Left side suffix to selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_side_suffix(side=self.script.left_suffix)
self.info.display_msg(10)
self.report({"OPERATOR"}, self.info.messages[10])
return {"FINISHED"}
class MVBH_OT_set_right_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_right_suffix"
bl_label = "Set Right side suffix"
bl_description = "Set Right side suffix to selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_side_suffix(side=self.script.right_suffix)
self.info.display_msg(11)
self.report({"OPERATOR"}, self.info.messages[11])
return {"FINISHED"}
class MVBH_OT_set_center_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_center_suffix"
bl_label = "Set Center bone side suffix"
bl_description = "Set Center side suffix to selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_side_suffix(side=self.script.center_suffix)
self.info.display_msg(12)
self.report({"OPERATOR"}, self.info.messages[11])
return {"FINISHED"}
class MVBH_OT_remove_side_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.remove_side_suffix"
bl_label = "Remove side suffix"
bl_description = "Remove side suffix of selected bones if any assigned to the bone"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return{"CANCELLED"}
self.script.delete_side_suffixes()
return {"FINISHED"}
class MVBH_OT_add_root_bone(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.add_root_bone"
bl_label = "Add Root bone"
bl_description = "Add a Root bone to currently selected Armature"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.toggle_mode(objectmode=True)
if self.script.root_name in bpy.data.armatures[self.script.get_armature_name()].bones.keys():
self.info.display_err(3)
self.report({"ERROR"}, self.info.errors[3])
self.script.toggle_mode(editmode=True)
return{"CANCELLED"}
self.script.add_root_bone()
self.script.move_selected_bones_to_layer(
layer_number=self.script.root_layer,
layer_name=self.script.root_name)
self.info.display_msg(0)
self.report({"OPERATOR"}, self.info.messages[0])
return {"FINISHED"}
class MVBH_OT_add_prop_bone(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.add_prop_bone"
bl_label = "Add Property bone"
bl_description = "Add a Property bone to currently selected Armature"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.toggle_mode(objectmode=True)
if self.script.prop_name in bpy.data.armatures[self.script.get_armature_name()].bones.keys():
self.info.display_err(4)
self.report({"ERROR"}, self.info.errors[4])
self.script.toggle_mode(editmode=True)
return{"CANCELLED"}
self.script.toggle_mode(objectmode=True)
if self.script.root_name not in bpy.data.armatures[self.script.get_armature_name()].bones.keys():
self.info.display_err(7)
self.report({"ERROR"}, self.info.errors[7])
self.script.toggle_mode(editmode=True)
return{"CANCELLED"}
self.script.add_prop_bone()
self.script.move_selected_bones_to_layer(
layer_number=self.script.prop_layer,
layer_name=self.script.prop_name)
self.info.display_msg(1)
self.report({"OPERATOR"}, self.info.messages[1])
return {"FINISHED"}
class MVBH_OT_add_def_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.add_def_bones"
bl_label = "Add Deform Bones"
bl_description = "Add new Deform bones based on the selection"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(
prefix=self.script.def_prefix, duplicate=True, deform=True)
self.script.move_selected_bones_to_layer(
layer_number=self.script.def_layer,
layer_name=self.script.def_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(9)
self.report({"OPERATOR"}, self.info.messages[9])
return {"FINISHED"}
class MVBH_OT_add_tgt_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.add_tgt_bones"
bl_label = "Add Target Bones"
bl_description = "Add new Target bones based on the selection"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(
prefix=self.script.tgt_prefix, duplicate=True)
self.script.move_selected_bones_to_layer(
layer_number=self.script.tgt_layer,
layer_name=self.script.tgt_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(27)
self.report({"OPERATOR"}, self.info.messages[27])
return {"FINISHED"}
class MVBH_OT_add_ctl_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.add_ctl_bones"
bl_label = "Add Control bones"
bl_description = "Add new Control bones based on the selection"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(
prefix=self.script.ctl_prefix, duplicate=True)
self.script.move_selected_bones_to_layer(
layer_number=self.script.ctl_layer,
layer_name=self.script.ctl_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(8)
self.report({"OPERATOR"}, self.info.messages[4])
return {"FINISHED"}
class MVBH_OT_add_mch_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.add_mch_bones"
bl_label = "Add Mechanism bones"
bl_description = "Add new Mechanism bones based on the selection"
bl_options = {"REGISTER", "UNDO"}
delete: bpy.props.BoolProperty(
name="Delete Constraints",
description="Delete constraints that have been previously assigned the the bone",
default=False
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.make_bone_group(
prefix=self.script.mch_prefix, duplicate=True)
self.script.move_selected_bones_to_layer(
layer_number=self.script.mch_layer,
layer_name=self.script.mch_prefix)
if self.delete:
self.script.delete_all_constraints()
self.info.display_msg(5)
self.report({"OPERATOR"}, self.info.messages[5])
return {"FINISHED"}
class MVBH_OT_set_copy_transforms_hierarchy(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_copy_transforms_hierarchy"
bl_label = "Set Copy Transform Hierarchy"
bl_description = "Set copy transforms constraints depending on the bone hierarchy selected by user that goes as follows: DEF<-TGT<-MCH<-CTL"
bl_options = {"REGISTER", "UNDO"}
use_local_space: bpy.props.BoolProperty(
name="Use Local Space",
description="Toggle Use Local Space instead of World Space",
default=False,
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_copy_constraint_hierarchy(
copy_trans=True, local_space=self.use_local_space
)
self.info.display_msg(20)
self.report({"OPERATOR"}, self.info.messages[20])
return{"FINISHED"}
class MVBH_OT_set_copy_rotation_hierarchy(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_copy_rotation_hierarchy"
bl_label = "Set Copy Rotation Hierarchy"
bl_description = "Set copy rotation constraints depending on the bone hierarchy selected by user that goes as follows: DEF<-TGT<-MCH<-CTL"
bl_options = {"REGISTER", "UNDO"}
use_local_space: bpy.props.BoolProperty(
name="Use Local Space",
description="Toggle Use Local Space instead of World Space",
default=False,
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_copy_constraint_hierarchy(
copy_rot=True, local_space=self.use_local_space
)
self.info.display_msg(22)
self.report({"OPERATOR"}, self.info.messages[22])
return{"FINISHED"}
class MVBH_OT_set_copy_location_hierarchy(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_copy_location_hierarchy"
bl_label = "Set Copy Location Hierarchy"
bl_description = "Set copy location constraints depending on the bone hierarchy selected by user that goes as follows: DEF<-TGT<-MCH<-CTL"
bl_options = {"REGISTER", "UNDO"}
use_local_space: bpy.props.BoolProperty(
name="Use Local Space",
description="Toggle Use Local Space instead of World Space",
default=False,
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_copy_constraint_hierarchy(
copy_loc=True, local_space=self.use_local_space
)
self.info.display_msg(23)
self.report({"OPERATOR"}, self.info.messages[23])
return{"FINISHED"}
class MVBH_OT_set_copy_scale_hierarchy(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_copy_scale_hierarchy"
bl_label = "Set Copy Scale Hierarchy"
bl_description = "Set Copy Scale Constraints depending on the bone hierarchy selected by user that goes as follows: DEF<-TGT<-MCH<-CTL"
bl_options = {"REGISTER", "UNDO"}
use_local_space: bpy.props.BoolProperty(
name="Use Local Space",
description="Toggle Use Local Space instead of World Space",
default=False,
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_copy_constraint_hierarchy(
copy_scale=True, local_space=self.use_local_space
)
self.info.display_msg(24)
self.report({"OPERATOR"}, self.info.messages[24])
return{"FINISHED"}
class MVBH_OT_set_ik_chain(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_ik_chain"
bl_label = "Set IK Chain"
bl_description = "Add IK chain to bones with: MCH-prefix and IK-suffix, CTL-prefix and IK-suffix, CTL-prefix and Pole-suffix"
bl_options = {"REGISTER", "UNDO"}
chain_len: bpy.props.IntProperty(
name="Chain Length",
description="Size of IK Chain",
default=2,
)
def execute(self, context):
if self.check_errors():
return{"CANCELLED"}
if len(self.script.get_selected_bones()) != 3:
self.script.info.display_err(8)
self.report({"ERROR"}, self.info.errors[8])
return{"CANCELLED"}
selection = self.script.get_selected_bones()
mch_check = False
ctl_check = False
pole_check = False
for bone in selection:
if self.script.mch_prefix in bone.name and self.script.ik_suffix in bone.name:
mch_check = True
elif self.script.ctl_prefix in bone.name and self.script.ik_suffix in bone.name:
ctl_check = True
elif self.script.ctl_prefix in bone.name and self.script.pole_suffix in bone.name:
pole_check = True
if mch_check and ctl_check and pole_check:
self.script.add_ik_hierarchy(chain_len=self.chain_len)
self.script.info.display_msg(31)
self.report({"OPERATOR"}, self.info.messages[31])
return{"FINISHED"}
else:
self.script.info.display_err(9)
self.report({"ERROR"}, self.info.errors[9])
return{"CANCELLED"}
class MVBH_OT_remove_all_constraints(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.remove_all_constraints"
bl_label = "Remove all constraints"
bl_description = "Remove all constraints on selected bones"
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.delete_all_constraints()
return{"FINISHED"}
class MVBH_OT_set_def_tgt_hierarchy(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_def_tgt_hierarchy"
bl_label = "Set Deform and Target bone Hierarchy"
bl_description = "Set copy transforms constraints to all currently selected Deform and Target bones. Parent Deform bones to Root bone"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_def_tgt_hierarchy()
self.info.display_msg(21)
self.report({"OPERATOR"}, self.info.messages[21])
return{"FINISHED"}
class MVBH_OT_parent_to_root_bone(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.parent_to_root_bone"
bl_label = "Parent to Root bone"
bl_description = "Parent all currently selected bones to ROOT bone"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.toggle_mode(objectmode=True)
if self.script.root_name not in bpy.data.armatures[self.script.get_armature_name()].bones.keys():
self.info.display_err(6)
self.report({"ERROR"}, self.info.errors[6])
self.script.toggle_mode(editmode=True)
return{"CANCELLED"}
self.script.parent_selected_bones_to_root()
self.info.display_msg(7)
self.report({"OPERATOR"}, self.info.messages[7])
return{"FINISHED"}
class MVBH_OT_set_ik_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_ik_suffix"
bl_label = "Set IK bone type suffix"
bl_description = "Set IK bone suffix to currently selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_bone_suffix(self.script.ik_suffix)
self.script.move_selected_bones_to_layer(
self.script.ik_layer, self.script.ik_suffix)
self.info.display_msg(13)
self.report({"OPERATOR"}, self.info.messages[13])
return{"FINISHED"}
class MVBH_OT_set_fk_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_fk_suffix"
bl_label = "Set FK bone type suffix"
bl_description = "Set FK bone suffix to currently selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_bone_suffix(self.script.fk_suffix)
self.script.move_selected_bones_to_layer(
self.script.ctl_layer, self.script.ctl_prefix)
self.info.display_msg(14)
self.report({"OPERATOR"}, self.info.messages[14])
return{"FINISHED"}
class MVBH_OT_set_twk_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_twk_suffix"
bl_label = "Set Tweak bone type suffix"
bl_description = "Set Tweak bone suffix to currently selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_bone_suffix(self.script.twk_suffix)
self.script.move_selected_bones_to_layer(
self.script.twk_layer, self.script.twk_suffix)
self.info.display_msg(15)
self.report({"OPERATOR"}, self.info.messages[15])
return{"FINISHED"}
class MVBH_OT_set_swtch_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_swtch_suffix"
bl_label = "Set Tweak bone type suffix"
bl_description = "Set Tweak bone suffix to currently selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_bone_suffix(self.script.swtch_suffix)
self.script.move_selected_bones_to_layer(
self.script.swtch_layer, self.script.swtch_suffix)
self.info.display_msg(16)
self.report({"OPERATOR"}, self.info.messages[16])
return{"FINISHED"}
class MVBH_OT_set_pole_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.set_pole_suffix"
bl_label = "Set Pole bone type suffix"
bl_description = "Set Pole bone suffix to currently selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.set_bone_suffix(self.script.pole_suffix)
self.script.move_selected_bones_to_layer(
self.script.pole_layer, self.script.pole_suffix)
self.info.display_msg(18)
self.report({"OPERATOR"}, self.info.messages[18])
return{"FINISHED"}
class MVBH_OT_remove_function_suffix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.remove_function_suffix"
bl_label = "Remove bone function suffix"
bl_description = "Remove bone function suffix if one is currently assigned to the selected bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.delete_function_suffixes()
return{"FINISHED"}
class MVBH_OT_select_left(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_left"
bl_label = "Select Left Side"
bl_description = "Select bones with Left side suffix"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.left_suffix)
return{"FINISHED"}
class MVBH_OT_select_right(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_right"
bl_label = "Select Right Side"
bl_description = "Select bones with Right side suffix"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.right_suffix)
return{"FINISHED"}
class MVBH_OT_select_center(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_center"
bl_label = "Select Center side"
bl_description = "Select bones with Center side suffix"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.center_suffix)
return{"FINISHED"}
class MVBH_OT_select_def(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_def"
bl_label = "Select Deform bones"
bl_description = "Select all Deform bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_prefix(
bone_prefix=self.script.def_prefix)
return{"FINISHED"}
class MVBH_OT_select_tgt(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_tgt"
bl_label = "Select Target bones"
bl_description = "Select all Target bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_prefix(
bone_prefix=self.script.tgt_prefix)
return{"FINISHED"}
class MVBH_OT_select_ctl(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_ctl"
bl_label = "Select Control bones"
bl_description = "Select all Control bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_prefix(
bone_prefix=self.script.ctl_prefix)
return{"FINISHED"}
class MVBH_OT_select_mch(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_mch"
bl_label = "Select Mechanism bones"
bl_description = "Select all Mechanism bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_prefix(
bone_prefix=self.script.mch_prefix)
return{"FINISHED"}
class MVBH_OT_select_ik(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_ik"
bl_label = "Select IK bones"
bl_description = "Select all IK bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.ik_suffix)
return{"FINISHED"}
class MVBH_OT_select_fk(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_fk"
bl_label = "Select IK bones"
bl_description = "Select all FK bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.fk_suffix)
return{"FINISHED"}
class MVBH_OT_select_twk(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_twk"
bl_label = "Select Tweak bones"
bl_description = "Select all Tweak bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.twk_suffix)
return{"FINISHED"}
class MVBH_OT_select_swtch(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_swtch"
bl_label = "Select Switch bones"
bl_description = "Select all Switch bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.swtch_suffix)
return{"FINISHED"}
class MVBH_OT_select_pole(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.select_pole"
bl_label = "Select Pole bones"
bl_description = "Select all Pole bones"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.select_all_bones_by_suffix(
bone_suffix=self.script.pole_suffix)
return{"FINISHED"}
class MVBH_OT_remove_zeroes(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.remove_zeroes"
bl_label = "Remove Zeroes"
bl_description = "Get rid of Zeroes in selected bones names (OPTIONAL: all numbers)"
bl_options = {"REGISTER", "UNDO"}
all_num: bpy.props.BoolProperty(
name="Remove All Numbers",
description="Remove all numbers in the selected bones",
default=False,
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.replace_in_bone_names(value="0", target="")
if self.all_num:
sel_bones = self.script.get_selected_bones()
for bone in sel_bones:
digitless_name = "".join((x for x in bone.name if not x.isdigit()))
if "." in digitless_name:
digitless_name = digitless_name.replace(".", "")
bone.name = f"{digitless_name}"
self.info.display_msg(17)
self.report({"OPERATOR"}, self.info.messages[17])
return{"FINISHED"}
class MVBH_OT_enumerate_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.enumerate_bones"
bl_label = "Enumerate selected bones"
bl_description = "Enumerate selected bones in consequential order"
bl_option = {"REGISTER", "UNDO"}
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
self.script.enumerate_bones()
return{"FINISHED"}
class MVBH_OT_replace_bone_name(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.replace_bone_name"
bl_label = "Replace bone name"
bl_description = "Replace bone name to specified value in selected bones"
bl_option = {"REGISTER", "UNDO"}
target_name: bpy.props.StringProperty(
name="Old Name",
description="Old bone name to be replaced by new name",
default="Bone",
)
new_name: bpy.props.StringProperty(
name="New Name",
description="Replace old bone name to this value",
default="Bone",
)
def execute(self, context):
if self.check_errors():
return {"CANCELLED"}
selected_bones = self.script.get_selected_bones()
check_list = ["Spine", "Neck", "Head", "Jaw", "Shoulder", "Upper_limb", "Arm", "Forearm", "Hand", "Finger", "Pelvis", "Hip",
"Lower_limb", "Leg", "Thigh", "Knee", "Shin", "Ankle", "Toe", "Tail", "Ear", "Claw", "Eye", "Torso", "Chest", "Limb", "Foot"]
for bone in selected_bones:
if "Bone" not in bone.name:
for i in check_list:
if i in bone.name:
bone.name = bone.name.replace(i, self.new_name)
elif "Bone" in bone.name:
bone.name = bone.name.replace(self.target_name, self.new_name)
else:
pass
return{"FINISHED"}
class MVBH_OT_remove_bone_prefix(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.remove_bone_prefix"
bl_label = "Remove prefix"
bl_description = "Delete bone prefix if it corresponds to standard naming convention"
bl_option = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.remove_bone_prefix()
return{"FINISHED"}
class MVBH_OT_remove_ghost_bones(bpy.types.Operator, MVBH_Operator):
bl_idname = "mvbh.remove_ghost_bones"
bl_label = "Remove Ghost bones"
bl_description = "Purge previously modified or delete bone data, to fix renaming issues"
bl_option = {"REGISTER", "UNDO"}
def execute(self, context):
self.script.toggle_mode(objectmode=True)
self.script.delete_orphan_data()
self.script.toggle_mode(editmode=True)
return{"FINISHED"}