Cleanup: remove unused operator args
[blender-addons.git] / animation_animall.py
blob25fb9bd108bb7444f94f4535794eac56e08cb486
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 bl_info = {
20 "name": "AnimAll",
21 "author": "Daniel Salazar <zanqdo@gmail.com>",
22 "version": (0, 8),
23 "blender": (2, 73),
24 "location": "Tool bar > Animation tab > AnimAll",
25 "description": "Allows animation of mesh, lattice, curve and surface data",
26 "warning": "",
27 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
28 "Scripts/Animation/AnimAll",
29 "category": "Animation",
32 """-------------------------------------------------------------------------
33 Thanks to Campbell Barton and Joshua Leung for hes API additions and fixes
34 Daniel 'ZanQdo' Salazar
35 -------------------------------------------------------------------------"""
37 import bpy
38 from bpy.props import *
42 # Property Definitions
44 bpy.types.WindowManager.key_shape = BoolProperty(
45 name="Shape",
46 description="Insert keyframes on active Shape Key layer",
47 default=False)
49 bpy.types.WindowManager.key_uvs = BoolProperty(
50 name="UVs",
51 description="Insert keyframes on active UV coordinates",
52 default=False)
54 bpy.types.WindowManager.key_ebevel = BoolProperty(
55 name="E-Bevel",
56 description="Insert keyframes on edge bevel weight",
57 default=False)
59 bpy.types.WindowManager.key_vbevel = BoolProperty(
60 name="V-Bevel",
61 description="Insert keyframes on vertex bevel weight",
62 default=False)
64 bpy.types.WindowManager.key_crease = BoolProperty(
65 name="Crease",
66 description="Insert keyframes on edge creases",
67 default=False)
69 bpy.types.WindowManager.key_vcols = BoolProperty(
70 name="V-Cols",
71 description="Insert keyframes on active Vertex Color values",
72 default=False)
74 bpy.types.WindowManager.key_vgroups = BoolProperty(
75 name="V-Groups",
76 description="Insert keyframes on active Vertex Group values",
77 default=False)
79 bpy.types.WindowManager.key_points = BoolProperty(
80 name="Points",
81 description="Insert keyframes on point locations",
82 default=False)
84 bpy.types.WindowManager.key_radius = BoolProperty(
85 name="Radius",
86 description="Insert keyframes on point radius (Shrink/Fatten)",
87 default=False)
89 bpy.types.WindowManager.key_tilt = BoolProperty(
90 name="Tilt",
91 description="Insert keyframes on point tilt",
92 default=False)
95 # GUI (Panel)
97 class VIEW3D_PT_animall(bpy.types.Panel):
99 bl_space_type = 'VIEW_3D'
100 bl_region_type = 'TOOLS'
101 bl_category = "Animation"
102 bl_label = 'AnimAll'
103 #bl_options = {'DEFAULT_CLOSED'}
104 @classmethod
105 def poll(self, context):
106 if context.active_object and context.active_object.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'}:
107 return context.active_object.type
109 # draw the gui
110 def draw(self, context):
112 Obj = context.active_object
114 layout = self.layout
115 col = layout.column(align=True)
116 row = col.row()
118 if Obj.type == 'LATTICE':
119 row.prop(context.window_manager, "key_points")
120 row.prop(context.window_manager, "key_shape")
122 elif Obj.type == 'MESH':
123 row.prop(context.window_manager, "key_points")
124 row.prop(context.window_manager, "key_shape")
125 row = col.row()
126 row.prop(context.window_manager, "key_ebevel")
127 row.prop(context.window_manager, "key_vbevel")
128 col.prop(context.window_manager, "key_crease")
129 row = col.row()
130 row.prop(context.window_manager, "key_vcols")
131 row.prop(context.window_manager, "key_vgroups")
132 row = col.row()
133 row.prop(context.window_manager, "key_uvs")
135 elif Obj.type == 'CURVE':
136 row.prop(context.window_manager, "key_points")
137 row.prop(context.window_manager, "key_shape")
138 row = col.row()
139 row.prop(context.window_manager, "key_radius")
140 row.prop(context.window_manager, "key_tilt")
142 elif Obj.type == 'SURFACE':
143 row.prop(context.window_manager, "key_points")
144 row.prop(context.window_manager, "key_shape")
145 row = col.row()
146 row.prop(context.window_manager, "key_radius")
147 row.prop(context.window_manager, "key_tilt")
149 row = col.row()
150 row.operator('anim.insert_keyframe_animall', icon='KEY_HLT')
151 row.operator('anim.delete_keyframe_animall', icon='KEY_DEHLT')
152 row = layout.row()
153 row.operator('anim.clear_animation_animall', icon='X')
155 if context.window_manager.key_shape:
157 ShapeKey = Obj.active_shape_key
158 ShapeKeyIndex = Obj.active_shape_key_index
160 split = layout.split()
161 row = split.row()
163 if ShapeKeyIndex > 0:
164 row.label(ShapeKey.name, icon='SHAPEKEY_DATA')
165 row.prop(ShapeKey, "value", text="")
166 row.prop(Obj, "show_only_shape_key", text="")
167 if ShapeKey.value < 1:
168 row = layout.row()
169 row.label('Maybe set "%s" to 1.0?' % ShapeKey.name, icon='INFO')
170 elif ShapeKey:
171 row.label('Can not key on Basis Shape', icon='ERROR')
172 else:
173 row.label('No active Shape Key', icon='ERROR')
175 if context.window_manager.key_points and context.window_manager.key_shape:
176 row = layout.row()
177 row.label('"Points" and "Shape" are redundant?', icon='INFO')
180 class ANIM_OT_insert_keyframe_animall(bpy.types.Operator):
181 bl_label = 'Insert'
182 bl_idname = 'anim.insert_keyframe_animall'
183 bl_description = 'Insert a Keyframe'
184 bl_options = {'REGISTER', 'UNDO'}
187 # on mouse up:
188 def invoke(self, context, event):
190 self.execute(context)
192 return {'FINISHED'}
195 def execute(op, context):
197 Obj = context.active_object
199 if Obj.type == 'MESH':
200 Mode = False
201 if context.mode == 'EDIT_MESH':
202 Mode = not Mode
203 bpy.ops.object.editmode_toggle()
205 Data = Obj.data
207 if context.window_manager.key_shape:
208 if Obj.active_shape_key_index > 0:
209 for Vert in Obj.active_shape_key.data:
210 Vert.keyframe_insert('co')
212 if context.window_manager.key_points:
213 for Vert in Data.vertices:
214 Vert.keyframe_insert('co')
216 if context.window_manager.key_ebevel:
217 for Edge in Data.edges:
218 Edge.keyframe_insert('bevel_weight')
220 if context.window_manager.key_vbevel:
221 for Vert in Data.vertices:
222 Vert.keyframe_insert('bevel_weight')
224 if context.window_manager.key_crease:
225 for Edge in Data.edges:
226 Edge.keyframe_insert('crease')
228 if context.window_manager.key_vgroups:
229 for Vert in Data.vertices:
230 for Group in Vert.groups:
231 Group.keyframe_insert('weight')
233 if context.window_manager.key_uvs:
234 for UV in Data.uv_layers.active.data:
235 UV.keyframe_insert('uv')
237 if context.window_manager.key_vcols:
238 for VColLayer in Data.vertex_colors:
239 if VColLayer.active: # only insert in active VCol layer
240 for Data in VColLayer.data:
241 Data.keyframe_insert('color')
243 if Mode:
244 bpy.ops.object.editmode_toggle()
246 if Obj.type == 'LATTICE':
247 Mode = False
248 if context.mode != 'OBJECT':
249 Mode = not Mode
250 bpy.ops.object.editmode_toggle()
252 Data = Obj.data
254 if context.window_manager.key_shape:
255 if Obj.active_shape_key_index > 0:
256 for Point in Obj.active_shape_key.data:
257 Point.keyframe_insert('co')
259 if context.window_manager.key_points:
260 for Point in Data.points:
261 Point.keyframe_insert('co_deform')
263 if Mode:
264 bpy.ops.object.editmode_toggle()
266 if Obj.type in {'CURVE', 'SURFACE'}:
267 Mode = False
268 if context.mode != 'OBJECT':
269 Mode = not Mode
270 bpy.ops.object.editmode_toggle()
272 Data = Obj.data
274 # run this outside the splines loop (only once)
275 if context.window_manager.key_shape:
276 if Obj.active_shape_key_index > 0:
277 for CV in Obj.active_shape_key.data:
278 CV.keyframe_insert('co')
279 try: # in case spline has no handles
280 CV.keyframe_insert('handle_left')
281 CV.keyframe_insert('handle_right')
282 except: pass
284 for Spline in Data.splines:
285 if Spline.type == 'BEZIER':
287 for CV in Spline.bezier_points:
289 if context.window_manager.key_points:
290 CV.keyframe_insert('co')
291 CV.keyframe_insert('handle_left')
292 CV.keyframe_insert('handle_right')
294 if context.window_manager.key_radius:
295 CV.keyframe_insert('radius')
297 if context.window_manager.key_tilt:
298 CV.keyframe_insert('tilt')
300 elif Spline.type == 'NURBS':
302 for CV in Spline.points:
304 if context.window_manager.key_points:
305 CV.keyframe_insert('co')
307 if context.window_manager.key_radius:
308 CV.keyframe_insert('radius')
310 if context.window_manager.key_tilt:
311 CV.keyframe_insert('tilt')
313 if Mode:
314 bpy.ops.object.editmode_toggle()
317 return {'FINISHED'}
320 class ANIM_OT_delete_keyframe_animall(bpy.types.Operator):
321 bl_label = 'Delete'
322 bl_idname = 'anim.delete_keyframe_animall'
323 bl_description = 'Delete a Keyframe'
324 bl_options = {'REGISTER', 'UNDO'}
327 # on mouse up:
328 def invoke(self, context, event):
330 self.execute(context)
332 return {'FINISHED'}
335 def execute(op, context):
337 Obj = context.active_object
339 if Obj.type == 'MESH':
340 Mode = False
341 if context.mode == 'EDIT_MESH':
342 Mode = not Mode
343 bpy.ops.object.editmode_toggle()
345 Data = Obj.data
347 if context.window_manager.key_shape:
348 if Obj.active_shape_key:
349 for Vert in Obj.active_shape_key.data:
350 Vert.keyframe_delete('co')
352 if context.window_manager.key_points:
353 for Vert in Data.vertices:
354 Vert.keyframe_delete('co')
356 if context.window_manager.key_ebevel:
357 for Edge in Data.edges:
358 Edge.keyframe_delete('bevel_weight')
360 if context.window_manager.key_vbevel:
361 for Vert in Data.vertices:
362 Vert.keyframe_delete('bevel_weight')
364 if context.window_manager.key_crease:
365 for Edge in Data.edges:
366 Edge.keyframe_delete('crease')
368 if context.window_manager.key_vgroups:
369 for Vert in Data.vertices:
370 for Group in Vert.groups:
371 Group.keyframe_delete('weight')
373 if context.window_manager.key_uvs:
374 for UV in Data.uv_layers.active.data:
375 UV.keyframe_delete('uv')
377 if context.window_manager.key_vcols:
378 for VColLayer in Data.vertex_colors:
379 if VColLayer.active: # only delete in active VCol layer
380 for Data in VColLayer.data:
381 Data.keyframe_delete('color')
383 if Mode:
384 bpy.ops.object.editmode_toggle()
386 if Obj.type == 'LATTICE':
388 Mode = False
389 if context.mode != 'OBJECT':
390 Mode = not Mode
391 bpy.ops.object.editmode_toggle()
393 Data = Obj.data
395 if context.window_manager.key_shape:
396 if Obj.active_shape_key:
397 for Point in Obj.active_shape_key.data:
398 Point.keyframe_delete('co')
400 if context.window_manager.key_points:
401 for Point in Data.points:
402 Point.keyframe_delete('co_deform')
404 if Mode:
405 bpy.ops.object.editmode_toggle()
407 if Obj.type in {'CURVE', 'SURFACE'}:
408 Mode = False
409 if context.mode != 'OBJECT':
410 Mode = not Mode
411 bpy.ops.object.editmode_toggle()
413 Data = Obj.data
415 # run this outside the splines loop (only once)
416 if context.window_manager.key_shape:
417 if Obj.active_shape_key_index > 0:
418 for CV in Obj.active_shape_key.data:
419 CV.keyframe_delete('co')
420 try: # in case spline has no handles
421 CV.keyframe_delete('handle_left')
422 CV.keyframe_delete('handle_right')
423 except: pass
425 for Spline in Data.splines:
426 if Spline.type == 'BEZIER':
427 for CV in Spline.bezier_points:
428 if context.window_manager.key_points:
429 CV.keyframe_delete('co')
430 CV.keyframe_delete('handle_left')
431 CV.keyframe_delete('handle_right')
432 if context.window_manager.key_radius:
433 CV.keyframe_delete('radius')
434 if context.window_manager.key_tilt:
435 CV.keyframe_delete('tilt')
437 elif Spline.type == 'NURBS':
438 for CV in Spline.points:
439 if context.window_manager.key_points:
440 CV.keyframe_delete('co')
441 if context.window_manager.key_radius:
442 CV.keyframe_delete('radius')
443 if context.window_manager.key_tilt:
444 CV.keyframe_delete('tilt')
446 if Mode:
447 bpy.ops.object.editmode_toggle()
450 return {'FINISHED'}
453 class ANIM_OT_clear_animation_animall(bpy.types.Operator):
454 bl_label = 'Clear Animation'
455 bl_idname = 'anim.clear_animation_animall'
456 bl_description = 'Delete all keyframes for this object'
457 bl_options = {'REGISTER', 'UNDO'}
459 # on mouse up:
460 def invoke(self, context, event):
462 wm = context.window_manager
463 return wm.invoke_confirm(self, event)
466 def execute(op, context):
468 Data = context.active_object.data
469 Data.animation_data_clear()
471 return {'FINISHED'}
474 def register():
475 bpy.utils.register_module(__name__)
477 pass
479 def unregister():
480 bpy.utils.unregister_module(__name__)
482 pass
484 if __name__ == "__main__":
485 register()