forked from sambler/myblendercontrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_keying_set.py
164 lines (133 loc) · 5.85 KB
/
change_keying_set.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
#
# Copyright (c) 2016 Shane Ambler
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# made in response to
# http://blender.stackexchange.com/q/49541/935
bl_info = {
"version": (1, 2),
"blender": (2, 80, 0),
"author": "sambler",
"name": "Change Keying Sets",
"location": "3D view -> properties region",
"description": "A panel of buttons and shortcuts that change the active keying set.",
"warning": "",
"wiki_url": "https://github.com/sambler/addonsByMe/blob/master/change_keying_set.py",
"tracker_url": "https://github.com/sambler/addonsByMe/issues",
"category": "Animation",
}
import bpy
class SetKeyingSetOperator(bpy.types.Operator):
"""Set the active keying set"""
bl_idname = 'anim.set_keyingset'
bl_label = 'Set the active keying set'
type : bpy.props.StringProperty(default='LocRotScale')
def execute(self, context):
ks = context.scene.keying_sets_all
if self.type == '':
ks.active = None
else:
ks.active = ks[self.type]
return {'FINISHED'}
class KeyingsetsPanel(bpy.types.Panel):
"""Display some butons to set the active keying set"""
bl_label = 'Keying Set'
bl_idname = 'ANIM_PT_set_keyingset'
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw(self, context):
scn = context.scene
layout = self.layout
row = layout.row()
col = row.column()
col.label(text='Active Set:')
col = row.column()
if scn.keying_sets_all.active:
col.label(text=scn.keying_sets_all.active.bl_label)
else:
col.label(text='None')
# some preset buttons - add or adjust to what you use
row = layout.row()
row.operator('anim.set_keyingset', text='None').type = ''
row = layout.row()
row.operator('anim.set_keyingset', text='Location').type = 'Location'
row = layout.row()
row.operator('anim.set_keyingset', text='Rotation').type = 'Rotation'
row = layout.row()
row.operator('anim.set_keyingset', text='LocRot').type = 'LocRot'
row = layout.row()
row.operator('anim.set_keyingset', text='LocRotScale').type = 'LocRotScale'
# note that the bl_label of the keying set is used for the type
# for a list of available type values - paste this in blenders python console
# [k.bl_label for k in bpy.context.scene.keying_sets_all]
row = layout.row()
row.operator('anim.set_keyingset', text='WholeCharacter').type = 'Whole Character'
# store keymaps here to access after registration
addon_keymaps = []
def register():
bpy.utils.register_class(SetKeyingSetOperator)
bpy.utils.register_class(KeyingsetsPanel)
# some sample shortcuts - adjust to personal taste.
# As most keys have been assigned to various tasks I have
# chosen to setup modifier keys - hold K and press the shortcut key
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
# add keys for object mode
km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
kmi = km.keymap_items.new(SetKeyingSetOperator.bl_idname, 'Y',
'PRESS', key_modifier='K')
kmi.properties.type = 'Location'
addon_keymaps.append((km, kmi))
kmi = km.keymap_items.new(SetKeyingSetOperator.bl_idname, 'U',
'PRESS', key_modifier='K')
kmi.properties.type = 'Rotation'
addon_keymaps.append((km, kmi))
kmi = km.keymap_items.new(SetKeyingSetOperator.bl_idname, 'I',
'PRESS', key_modifier='K')
kmi.properties.type = 'LocRotScale'
addon_keymaps.append((km, kmi))
# add keys for pose mode
km = wm.keyconfigs.addon.keymaps.new(name='Pose', space_type='EMPTY')
kmi = km.keymap_items.new(SetKeyingSetOperator.bl_idname, 'Y',
'PRESS', key_modifier='K')
kmi.properties.type = 'Location'
addon_keymaps.append((km, kmi))
kmi = km.keymap_items.new(SetKeyingSetOperator.bl_idname, 'U',
'PRESS', key_modifier='K')
kmi.properties.type = 'Rotation'
addon_keymaps.append((km, kmi))
kmi = km.keymap_items.new(SetKeyingSetOperator.bl_idname, 'I',
'PRESS', key_modifier='K')
kmi.properties.type = 'LocRotScale'
addon_keymaps.append((km, kmi))
def unregister():
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
bpy.utils.unregister_class(KeyingsetsPanel)
bpy.utils.unregister_class(SetKeyingSetOperator)
if __name__ == "__main__":
register()