-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshift_keyframes.py
More file actions
executable file
·232 lines (186 loc) · 7.76 KB
/
shift_keyframes.py
File metadata and controls
executable file
·232 lines (186 loc) · 7.76 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# <pep8 compliant>
bl_info = {
"name": "Shift Keyframes",
"description": "Shift keyframes left/right via hotkeys",
"author": "Amaral Krichman",
"version": (1, 0, 1),
"blender": (2, 80, 0),
"location": "Dopesheet/Graph Editor > Key > Transform",
"warning": "",
"wiki_url": "",
"category": "Animation",
}
import bpy
class GRAPH_OT_keyframe_shift(bpy.types.Operator):
'''Shift Keyframe'''
bl_idname = "graph.keyframe_shift"
bl_label = "Shift Keyframes"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
#| n of frames to shift | direction to shift them | direction axis (x or y)
distance: bpy.props.IntProperty(default=1)
backwards: bpy.props.BoolProperty(default=False)
axis: bpy.props.BoolProperty(default=False)
selected = []
@classmethod
def poll(cls, context):
return context.area.type in {'DOPESHEET_EDITOR', 'GRAPH_EDITOR'}
def fetch_selected(self):
self.selected.clear()
for action in bpy.data.actions:
for channel in action.fcurves:
for key in channel.keyframe_points:
if key.select_control_point == True:
self.selected.append(key)
#vertical dimension, dormant for now
def move(self, amount, reverse, axis):
self.ax = int(axis)
for k in self.selected:
if not reverse:
k.co[self.ax] += amount
if axis:
k.handle_left.y += amount
k.handle_right.y += amount
else:
k.handle_left.x += amount
k.handle_right.x += amount
else:
k.co[self.ax] -= amount
if axis:
k.handle_left.y -= amount
k.handle_right.y -= amount
else:
k.handle_left.x -= amount
k.handle_right.x -= amount
def execute(self, _context):
self.fetch_selected()
self.move(self.distance, self.backwards, self.axis)
return {'FINISHED'}
class GRAPH_MT_keyframe_shift(bpy.types.Menu):
bl_label = "Shift"
bl_idname = "GRAPH_MT_keyframe_shift"
def draw(self, _context):
m = self.layout
idname = GRAPH_OT_keyframe_shift.bl_idname
r1 = m.operator(idname, text="Forward by 1")
r1.axis = False
r1.backwards = False
r1.distance = 1
r10 = m.operator(idname, text="Forward by 10")
r10.axis = False
r10.distance = 10
r10.backwards = False
m.separator()
l1 = m.operator(idname, text="Backward by 1")
l1.axis = False
l1.backwards = True
l1.distance = 1
l10 = m.operator(idname, text="Backward by 10")
l10.axis = False
l10.backwards = True
l10.distance = 10
#---------------------Registration---------------------
def add_menu(self, _context):
self.layout.menu(GRAPH_MT_keyframe_shift.bl_idname)
addon_keymaps = []
classes = (GRAPH_OT_keyframe_shift, GRAPH_MT_keyframe_shift)
def register():
for c in classes:
bpy.utils.register_class(c)
bpy.types.GRAPH_MT_key_transform.prepend(add_menu)
bpy.types.DOPESHEET_MT_key_transform.prepend(add_menu)
kc = bpy.context.window_manager.keyconfigs.addon
km_1 = kc.keymaps.new(name='Graph Editor', space_type='GRAPH_EDITOR')
km_2 = kc.keymaps.new(name='Dopesheet', space_type='DOPESHEET_EDITOR')
idname = GRAPH_OT_keyframe_shift.bl_idname
#Graph
kmi_1_R = km_1.keymap_items.new(idname, 'RIGHT_ARROW', 'PRESS', alt=True)
kmi_1_R.properties.distance = 1
kmi_1_R.properties.backwards = False
kmi_1_R.properties.axis = False
kmi_1_RR = km_1.keymap_items.new(idname, 'RIGHT_ARROW', 'PRESS', shift=True, alt=True)
kmi_1_RR.properties.distance = 10
kmi_1_RR.properties.backwards = False
kmi_1_RR.properties.axis = False
kmi_1_L = km_1.keymap_items.new(idname, 'LEFT_ARROW', 'PRESS', alt=True)
kmi_1_L.properties.distance = 1
kmi_1_L.properties.backwards = True
kmi_1_L.properties.axis = False
kmi_1_LL = km_1.keymap_items.new(idname, 'LEFT_ARROW', 'PRESS', shift=True, alt=True)
kmi_1_LL.properties.distance = 10
kmi_1_LL.properties.backwards = True
kmi_1_LL.properties.axis = False
# kmi_1_U = km_2.keymap_items.new(idname, 'UP_ARROW', 'PRESS', alt=True)
# kmi_1_U.properties.distance = 1
# kmi_1_U.properties.backwards = False
# kmi_1_U.properties.axis = True
#
# kmi_1_UU = km_2.keymap_items.new(idname, 'UP_ARROW', 'PRESS', shift=True, alt=True)
# kmi_1_UU.properties.distance = 10
# kmi_1_UU.properties.backwards = False
# kmi_1_UU.properties.axis = True
#
# kmi_1_D = km_2.keymap_items.new(idname, 'DOWN_ARROW', 'PRESS', alt=True)
# kmi_1_D.properties.distance = 1
# kmi_1_D.properties.backwards = True
# kmi_1_D.properties.axis = True
#
# kmi_1_DD = km_2.keymap_items.new(idname, 'DOWN_ARROW', 'PRESS', shift=True, alt=True)
# kmi_1_DD.properties.distance = 10
# kmi_1_DD.properties.backwards = True
# kmi_1_DD.properties.axis = True
#Dope
kmi_2_R = km_2.keymap_items.new(idname, 'RIGHT_ARROW', 'PRESS', alt=True)
kmi_2_R.properties.distance = 1
kmi_2_R.properties.backwards = False
kmi_2_R.properties.axis = False
kmi_2_RR = km_2.keymap_items.new(idname, 'RIGHT_ARROW', 'PRESS', shift=True, alt=True)
kmi_2_RR.properties.distance = 10
kmi_2_RR.properties.backwards = False
kmi_2_RR.properties.axis = False
kmi_2_L = km_2.keymap_items.new(idname, 'LEFT_ARROW', 'PRESS', alt=True)
kmi_2_L.properties.distance = 1
kmi_2_L.properties.backwards = True
kmi_2_L.properties.axis = False
kmi_2_LL = km_2.keymap_items.new(idname, 'LEFT_ARROW', 'PRESS', shift=True, alt=True)
kmi_2_LL.properties.distance = 10
kmi_2_LL.properties.backwards = True
kmi_2_LL.properties.axis = False
# kmi_2_U = km_2.keymap_items.new(idname, 'UP_ARROW', 'PRESS', alt=True)
# kmi_2_U.properties.distance = 1
# kmi_2_U.properties.backwards = False
# kmi_2_U.properties.axis = True
#
# kmi_2_UU = km_2.keymap_items.new(idname, 'UP_ARROW', 'PRESS', shift=True, alt=True)
# kmi_2_UU.properties.distance = 10
# kmi_2_UU.properties.backwards = False
# kmi_2_UU.properties.axis = True
#
# kmi_2_D = km_2.keymap_items.new(idname, 'DOWN_ARROW', 'PRESS', alt=True)
# kmi_2_D.properties.distance = 1
# kmi_2_D.properties.backwards = True
# kmi_2_D.properties.axis = True
#
# kmi_2_DD = km_2.keymap_items.new(idname, 'DOWN_ARROW', 'PRESS', shift=True, alt=True)
# kmi_2_DD.properties.distance = 10
# kmi_2_DD.properties.backwards = True
# kmi_2_DD.properties.axis = True
addon_keymaps.append((km_1, km_2))
def unregister():
for c in classes:
bpy.utils.unregister_class(c)
bpy.types.GRAPH_MT_key_transform.remove(add_menu)
bpy.types.DOPESHEET_MT_key_transform.remove(add_menu)
if __name__ == "__main__":
register()