forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBONE_PT_context_bone.py
152 lines (126 loc) · 4.66 KB
/
BONE_PT_context_bone.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
# 「プロパティ」エリア > 「ボーン」タブ
# "Propaties" Area > "Bone" Tab
import bpy
import re
from bpy.props import *
from bpy.ops import *
################
# オペレーター #
################
class CopyBoneName(bpy.types.Operator):
bl_idname = "object.copy_bone_name"
bl_label = "Copy Bone Name to Clipboard"
bl_description = "Copy the active bone's name to Clipboard"
bl_options = {'REGISTER', 'UNDO'}
isObject : BoolProperty(name="Contain Object Name", default=False)
@classmethod
def poll(cls, context):
if (context.active_bone):
return True
elif (context.active_pose_bone):
return True
return False
def execute(self, context):
if (context.active_bone):
context.window_manager.clipboard = context.active_bone.name
elif (context.active_pose_bone):
context.window_manager.clipboard = context.active_pose_bone.name
if (self.isObject):
context.window_manager.clipboard = f"{context.active_object.name}:{context.window_manager.clipboard}"
self.report(type={'INFO'}, message=context.window_manager.clipboard)
return {'FINISHED'}
class RenameMirrorActiveBone(bpy.types.Operator):
bl_idname = "pose.rename_mirror_active_bone"
bl_label = "Flip Bone Name's Axis Suffix"
bl_description = "Flip the axis suffix of the active bone's name"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
if (context.active_bone):
bone = context.active_bone
if (context.active_pose_bone):
bone = context.active_pose_bone
pre_name = bone.name
if context.active_object.mode == "EDIT":
bpy.ops.armature.flip_names(do_strip_numbers=False)
elif context.active_object.mode == "POSE":
bpy.ops.pose.flip_names(do_strip_numbers=False)
if (pre_name != bone.name):
self.report(type={'INFO'}, message=pre_name + " => " + bone.name)
else:
self.report(type={'ERROR'}, message="Flipping the suffix failed")
return {'CANCELLED'}
return {'FINISHED'}
class AppendActiveBoneName(bpy.types.Operator):
bl_idname = "pose.append_active_bone_name"
bl_label = "Add Axis Suffix to Bone Name"
bl_description = "Add an axis suffix to the active bone's name"
bl_options = {'REGISTER', 'UNDO'}
string : StringProperty(name="Axis suffix")
@classmethod
def poll(self, context):
if (context.active_bone):
return True
if (context.active_pose_bone):
return True
return False
def execute(self, context):
if (context.active_bone):
bone = context.active_bone
if (context.active_pose_bone):
bone = context.active_pose_bone
bone.name = bone.name + self.string
return {'FINISHED'}
################
# サブメニュー #
################
class AppendNameMenu(bpy.types.Menu):
bl_idname = "BONE_MT_context_bone_append_name"
bl_label = "Add Axis Suffix"
bl_description = "Adds an axis suffix to the active bone's name"
def draw(self, context):
self.layout.operator(AppendActiveBoneName.bl_idname, text=".L").string = '.L'
self.layout.operator(AppendActiveBoneName.bl_idname, text=".R").string = '.R'
self.layout.separator()
self.layout.operator(AppendActiveBoneName.bl_idname, text="_L").string = '_L'
self.layout.operator(AppendActiveBoneName.bl_idname, text="_R").string = '_R'
self.layout.separator()
self.layout.operator(AppendActiveBoneName.bl_idname, text=".left").string = '.left'
self.layout.operator(AppendActiveBoneName.bl_idname, text=".right").string = '.right'
self.layout.separator()
self.layout.operator(AppendActiveBoneName.bl_idname, text="_left").string = '_left'
self.layout.operator(AppendActiveBoneName.bl_idname, text="_right").string = '_right'
################
# クラスの登録 #
################
classes = [
CopyBoneName,
RenameMirrorActiveBone,
AppendActiveBoneName,
AppendNameMenu
]
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])):
if (context.edit_bone or context.bone):
row = self.layout.row(align=True)
row.operator(CopyBoneName.bl_idname, icon='COPYDOWN', text="To Clipboard")
row.operator(RenameMirrorActiveBone.bl_idname, icon='MOD_MIRROR', text="Flip Axis Suffix")
row.menu(AppendNameMenu.bl_idname, icon='PLUGIN')
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]