forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVIEW3D_MT_pose_showhide.py
104 lines (86 loc) · 2.98 KB
/
VIEW3D_MT_pose_showhide.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
# 「3Dビュー」エリア > 「ポーズ」モード > 「ポーズ」メニュー > 「表示/隠す」メニュー
# "3D View" Area > "Pose" Mode > "Pose" Menu > "Show/Hide" Menu
import bpy
from bpy.props import *
################
# オペレーター #
################
class HideSelectBones(bpy.types.Operator):
bl_idname = "armature.hide_select_bones"
bl_label = "Restrict Selecting (Selected)"
bl_description = "Make selected bones unselectable"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
for bone in context.selected_pose_bones:
context.active_object.data.bones[bone.name].hide_select = True
return {'FINISHED'}
class HideNonSelectBones(bpy.types.Operator):
bl_idname = "armature.hide_non_select_bones"
bl_label = "Restrict Selecting (Non-Selected)"
bl_description = "Make unselected bones unselectable"
bl_options = {'REGISTER', 'UNDO'}
limit_to_view : BoolProperty(name="Not apply to undisplayed bones", default=True)
def draw(self, layout):
self.layout.prop(self, 'limit_to_view')
def execute(self, context):
arma = context.active_object.data
bones = arma.bones
selected = [bones[b.name] for b in context.selected_pose_bones]
if self.limit_to_view:
targets = []
import pprint
for bone in list(set(bones) - set(selected)):
if bone.hide:
continue
for ly_b, ly_a in zip(bone.layers[:], arma.layers[:]):
if ly_b and ly_a and ly_b == ly_a:
targets.append(bone)
break
else:
targets = list(set(bones) - set(selected))
for bone in targets:
bone.hide_select = True
return {'FINISHED'}
class HideSelectAllReset(bpy.types.Operator):
bl_idname = "armature.hide_select_all_reset"
bl_label = "Allow Selecting (All)"
bl_description = "Make all bones selectable"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
for bone in context.active_object.data.bones:
bone.hide_select = False
return {'FINISHED'}
################
# クラスの登録 #
################
classes = [
HideSelectBones,
HideNonSelectBones,
HideSelectAllReset
]
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])):
self.layout.separator()
self.layout.operator(HideSelectBones.bl_idname, icon="PLUGIN")
self.layout.operator(HideNonSelectBones.bl_idname, icon="PLUGIN")
self.layout.operator(HideSelectAllReset.bl_idname, icon="PLUGIN")
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.separator()
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]