forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDATA_PT_pose_library.py
125 lines (107 loc) · 3.79 KB
/
DATA_PT_pose_library.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 > "Pose Library" Panel
import bpy
from bpy.props import *
################
# オペレーター #
################
class MoveActivePose(bpy.types.Operator):
bl_idname = "poselib.move_active_pose"
bl_label = "Move Pose"
bl_description = "Move the pose up or down in the active Pose Library"
bl_options = {'REGISTER'}
is_up : BoolProperty(name="To Up", default=False)
@classmethod
def poll(cls, context):
if (not context.object):
return False
if (not context.object.pose_library):
return False
if (len(context.object.pose_library.pose_markers) < 2):
return False
return True
def execute(self, context):
pose_markers = context.object.pose_library.pose_markers
source = pose_markers.active
if (not self.is_up):
if (pose_markers.active_index < len(pose_markers)-1):
target = pose_markers[pose_markers.active_index+1]
pose_markers.active_index += 1
else:
return {'CANCELLED'}
else:
if (0 < pose_markers.active_index):
target = pose_markers[pose_markers.active_index-1]
pose_markers.active_index -= 1
else:
return {'CANCELLED'}
for data_name in dir(source):
if (data_name[0] != "_" and "rna" not in data_name):
temp_source = source.__getattribute__(data_name)
temp_target = target.__getattribute__(data_name)
source.__setattr__(data_name, temp_target)
target.__setattr__(data_name, temp_source)
return {'FINISHED'}
class MoveActivePoseMost(bpy.types.Operator):
bl_idname = "poselib.move_active_pose_most"
bl_label = "Move Pose to Top / Bottom"
bl_description = "Move the pose to top or bottom of the active pose library"
bl_options = {'REGISTER'}
is_top : BoolProperty(name="Move to Top", default=False)
@classmethod
def poll(cls, context):
if (not context.object):
return False
if (not context.object.pose_library):
return False
if (len(context.object.pose_library.pose_markers) < 2):
return False
return True
def execute(self, context):
pose_markers = context.object.pose_library.pose_markers
if (not self.is_top):
for i in range(len(pose_markers)-pose_markers.active_index):
bpy.ops.poselib.move_active_pose(is_up=False)
else:
for i in range(pose_markers.active_index):
bpy.ops.poselib.move_active_pose(is_up=True)
return {'FINISHED'}
################
# クラスの登録 #
################
classes = [
MoveActivePose,
MoveActivePoseMost
]
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.object):
if (context.object.pose_library):
if (len(context.object.pose_library.pose_markers)):
sp = self.layout.split(factor=0.15)
row = sp.row()
row.alignment = 'CENTER'
row.operator(MoveActivePose.bl_idname, icon='TRIA_UP', text="").is_up = True
row.operator(MoveActivePose.bl_idname, icon='TRIA_DOWN', text="").is_up = False
row = sp.row()
row.operator(MoveActivePoseMost.bl_idname, icon='TRIA_UP_BAR', text="Move to Top").is_top = True
row.operator(MoveActivePoseMost.bl_idname, icon='TRIA_DOWN_BAR', text="Move to Bottom").is_top = False
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]