forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDATA_PT_bone_groups.py
125 lines (107 loc) · 3.59 KB
/
DATA_PT_bone_groups.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
# 「プロパティ」エリア > 「アーマチュアデータ」タブ > 「ボーングループ」パネル
# "Propaties" Area > "Armature" Tab > "Bone Groups" Panel
import bpy
from bpy.props import *
################
# オペレーター #
################
class BoneGroupOnlyShow(bpy.types.Operator):
bl_idname = "pose.bone_group_only_show"
bl_label = "Show only bone in the bones group"
bl_description = "Show or hide ONLY the bones in the active Bone Group"
bl_options = {'REGISTER', 'UNDO'}
reverse : BoolProperty(name="Invert", default=False)
@classmethod
def poll(cls, context):
if (context.active_object):
if (context.active_object.type == 'ARMATURE'):
if (len(context.active_object.pose.bone_groups)):
return True
return False
def execute(self, context):
obj = context.active_object
arm = obj.data
for pbone in obj.pose.bones:
bone = arm.bones[pbone.name]
for i in range(len(arm.layers)):
if (arm.layers[i] and bone.layers[i]):
if (not pbone.bone_group):
if (not self.reverse):
bone.hide = True
else:
bone.hide = False
break
if (obj.pose.bone_groups.active.name == pbone.bone_group.name):
if (not self.reverse):
bone.hide = False
else:
bone.hide = True
else:
if (not self.reverse):
bone.hide = True
else:
bone.hide = False
break
return {'FINISHED'}
class BoneGroupShow(bpy.types.Operator):
bl_idname = "pose.bone_group_show"
bl_label = "Show bone in the bone group"
bl_description = "Show or hide the bones in the active Bone Group"
bl_options = {'REGISTER', 'UNDO'}
reverse : BoolProperty(name="Invert", default=False)
@classmethod
def poll(cls, context):
if (context.active_object):
if (context.active_object.type == 'ARMATURE'):
if (len(context.active_object.pose.bone_groups)):
return True
return False
def execute(self, context):
obj = context.active_object
arm = obj.data
for pbone in obj.pose.bones:
bone = arm.bones[pbone.name]
for i in range(len(arm.layers)):
if (arm.layers[i] and bone.layers[i]):
if (pbone.bone_group):
if (obj.pose.bone_groups.active.name == pbone.bone_group.name):
if (not self.reverse):
bone.hide = False
else:
bone.hide = True
return {'FINISHED'}
################
# クラスの登録 #
################
classes = [
BoneGroupOnlyShow,
BoneGroupShow
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
################
# メニュー追加 #
################
# メニューのオン/オフの判定
def IsMenuEnable(self_id):
for id in bpy.context.preferences.addons[__name__.partition('.')[0]].preferences.disabled_menu.split(','):
if (id == self_id):
return False
else:
return True
# メニューを登録する関数
def menu(self, context):
if (IsMenuEnable(__name__.split('.')[-1])):
row = self.layout.split(factor=0.35)
sub = row.row(align=True)
sub.operator(BoneGroupShow.bl_idname, icon='RESTRICT_VIEW_OFF', text="Show").reverse = False
sub.operator(BoneGroupShow.bl_idname, icon='RESTRICT_VIEW_ON', text="Hide").reverse = True
sub = row.row(align=True)
sub.operator(BoneGroupOnlyShow.bl_idname, icon='RESTRICT_VIEW_OFF', text="Show Only Active").reverse = False
sub.operator(BoneGroupOnlyShow.bl_idname, icon='RESTRICT_VIEW_ON', text="Hide Only Active").reverse = True
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]