Screencast Keys Addon: Improved mouse silhouette, fixed box width to fit to text...
[blender-addons.git] / animation_animall.py
blob6f3706a6d42ed9bac055d962f55475c6eee36c74
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, 7),
23 "blender": (2, 69, 7),
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/Scripts/Animation/AnimAll',
28 'tracker_url': 'https://developer.blender.org/T24874',
29 'category': 'Animation'}
31 """-------------------------------------------------------------------------
32 Thanks to Campbell Barton and Joshua Leung for hes API additions and fixes
33 Daniel 'ZanQdo' Salazar
34 -------------------------------------------------------------------------"""
36 import bpy
37 from bpy.props import *
41 # Property Definitions
43 bpy.types.WindowManager.key_shape = BoolProperty(
44 name="Shape",
45 description="Insert keyframes on active Shape Key layer",
46 default=False)
48 bpy.types.WindowManager.key_uvs = BoolProperty(
49 name="UVs",
50 description="Insert keyframes on active UV coordinates",
51 default=False)
53 bpy.types.WindowManager.key_bevel = BoolProperty(
54 name="Bevel",
55 description="Insert keyframes on edge bevel weight",
56 default=False)
58 bpy.types.WindowManager.key_crease = BoolProperty(
59 name="Crease",
60 description="Insert keyframes on edge creases",
61 default=False)
63 bpy.types.WindowManager.key_vcols = BoolProperty(
64 name="VCols",
65 description="Insert keyframes on active Vertex Color values",
66 default=False)
68 bpy.types.WindowManager.key_vgroups = BoolProperty(
69 name="VGroups",
70 description="Insert keyframes on active Vertex Group values",
71 default=False)
73 bpy.types.WindowManager.key_points = BoolProperty(
74 name="Points",
75 description="Insert keyframes on point locations",
76 default=False)
78 bpy.types.WindowManager.key_radius = BoolProperty(
79 name="Radius",
80 description="Insert keyframes on point radius (Shrink/Fatten)",
81 default=False)
83 bpy.types.WindowManager.key_tilt = BoolProperty(
84 name="Tilt",
85 description="Insert keyframes on point tilt",
86 default=False)
89 # GUI (Panel)
91 class VIEW3D_PT_animall(bpy.types.Panel):
93 bl_space_type = 'VIEW_3D'
94 bl_region_type = 'TOOLS'
95 bl_category = "Animation"
96 bl_label = 'AnimAll'
97 #bl_options = {'DEFAULT_CLOSED'}
98 @classmethod
99 def poll(self, context):
100 if context.active_object and context.active_object.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'}:
101 return context.active_object.type
103 # draw the gui
104 def draw(self, context):
106 Obj = context.active_object
108 layout = self.layout
109 col = layout.column(align=True)
110 row = col.row()
112 if Obj.type == 'LATTICE':
113 row.prop(context.window_manager, "key_points")
114 row.prop(context.window_manager, "key_shape")
116 elif Obj.type == 'MESH':
117 row.prop(context.window_manager, "key_points")
118 row.prop(context.window_manager, "key_shape")
119 row = col.row()
120 row.prop(context.window_manager, "key_bevel")
121 row.prop(context.window_manager, "key_crease")
122 row = col.row()
123 row.prop(context.window_manager, "key_vcols")
124 row.prop(context.window_manager, "key_vgroups")
125 row = col.row()
126 row.prop(context.window_manager, "key_uvs")
128 elif Obj.type == 'CURVE':
129 row.prop(context.window_manager, "key_points")
130 row.prop(context.window_manager, "key_shape")
131 row = col.row()
132 row.prop(context.window_manager, "key_radius")
133 row.prop(context.window_manager, "key_tilt")
135 elif Obj.type == 'SURFACE':
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 row = col.row()
143 row.operator('anim.insert_keyframe_animall', icon='KEY_HLT')
144 row.operator('anim.delete_keyframe_animall', icon='KEY_DEHLT')
145 row = layout.row()
146 row.operator('anim.clear_animation_animall', icon='X')
148 if context.window_manager.key_shape:
150 ShapeKey = Obj.active_shape_key
151 ShapeKeyIndex = Obj.active_shape_key_index
153 split = layout.split()
154 row = split.row()
156 if ShapeKeyIndex > 0:
157 row.label(ShapeKey.name, icon='SHAPEKEY_DATA')
158 row.prop(ShapeKey, "value", text="")
159 row.prop(Obj, "show_only_shape_key", text="")
160 if ShapeKey.value < 1:
161 row = layout.row()
162 row.label('Maybe set "%s" to 1.0?' % ShapeKey.name, icon='INFO')
163 elif ShapeKey:
164 row.label('Can not key on Basis Shape', icon='ERROR')
165 else:
166 row.label('No active Shape Key', icon='ERROR')
168 if context.window_manager.key_points and context.window_manager.key_shape:
169 row = layout.row()
170 row.label('"Points" and "Shape" are redundant?', icon='INFO')
173 class ANIM_OT_insert_keyframe_animall(bpy.types.Operator):
174 bl_label = 'Insert'
175 bl_idname = 'anim.insert_keyframe_animall'
176 bl_description = 'Insert a Keyframe'
177 bl_options = {'REGISTER', 'UNDO'}
180 # on mouse up:
181 def invoke(self, context, event):
183 self.execute(context)
185 return {'FINISHED'}
188 def execute(op, context):
190 Obj = context.active_object
192 if Obj.type == 'MESH':
193 Mode = False
194 if context.mode == 'EDIT_MESH':
195 Mode = not Mode
196 bpy.ops.object.editmode_toggle()
198 Data = Obj.data
200 if context.window_manager.key_shape:
201 if Obj.active_shape_key_index > 0:
202 for Vert in Obj.active_shape_key.data:
203 Vert.keyframe_insert('co')
205 if context.window_manager.key_points:
206 for Vert in Data.vertices:
207 Vert.keyframe_insert('co')
209 if context.window_manager.key_bevel:
210 for Edge in Data.edges:
211 Edge.keyframe_insert('bevel_weight')
213 if context.window_manager.key_crease:
214 for Edge in Data.edges:
215 Edge.keyframe_insert('crease')
217 if context.window_manager.key_vgroups:
218 for Vert in Data.vertices:
219 for Group in Vert.groups:
220 Group.keyframe_insert('weight')
222 if context.window_manager.key_uvs:
223 for UV in Data.uv_layers.active.data:
224 UV.keyframe_insert('uv')
226 if context.window_manager.key_vcols:
227 for VColLayer in Data.vertex_colors:
228 if VColLayer.active: # only insert in active VCol layer
229 for Data in VColLayer.data:
230 Data.keyframe_insert('color')
232 if Mode:
233 bpy.ops.object.editmode_toggle()
235 if Obj.type == 'LATTICE':
236 Mode = False
237 if context.mode != 'OBJECT':
238 Mode = not Mode
239 bpy.ops.object.editmode_toggle()
241 Data = Obj.data
243 if context.window_manager.key_shape:
244 if Obj.active_shape_key_index > 0:
245 for Point in Obj.active_shape_key.data:
246 Point.keyframe_insert('co')
248 if context.window_manager.key_points:
249 for Point in Data.points:
250 Point.keyframe_insert('co_deform')
252 if Mode:
253 bpy.ops.object.editmode_toggle()
255 if Obj.type in {'CURVE', 'SURFACE'}:
256 Mode = False
257 if context.mode != 'OBJECT':
258 Mode = not Mode
259 bpy.ops.object.editmode_toggle()
261 Data = Obj.data
263 # run this outside the splines loop (only once)
264 if context.window_manager.key_shape:
265 if Obj.active_shape_key_index > 0:
266 for CV in Obj.active_shape_key.data:
267 CV.keyframe_insert('co')
268 try: # in case spline has no handles
269 CV.keyframe_insert('handle_left')
270 CV.keyframe_insert('handle_right')
271 except: pass
273 for Spline in Data.splines:
274 if Spline.type == 'BEZIER':
276 for CV in Spline.bezier_points:
278 if context.window_manager.key_points:
279 CV.keyframe_insert('co')
280 CV.keyframe_insert('handle_left')
281 CV.keyframe_insert('handle_right')
283 if context.window_manager.key_radius:
284 CV.keyframe_insert('radius')
286 if context.window_manager.key_tilt:
287 CV.keyframe_insert('tilt')
289 elif Spline.type == 'NURBS':
291 for CV in Spline.points:
293 if context.window_manager.key_points:
294 CV.keyframe_insert('co')
296 if context.window_manager.key_radius:
297 CV.keyframe_insert('radius')
299 if context.window_manager.key_tilt:
300 CV.keyframe_insert('tilt')
302 if Mode:
303 bpy.ops.object.editmode_toggle()
306 return {'FINISHED'}
309 class ANIM_OT_delete_keyframe_animall(bpy.types.Operator):
310 bl_label = 'Delete'
311 bl_idname = 'anim.delete_keyframe_animall'
312 bl_description = 'Delete a Keyframe'
313 bl_options = {'REGISTER', 'UNDO'}
316 # on mouse up:
317 def invoke(self, context, event):
319 self.execute(context)
321 return {'FINISHED'}
324 def execute(op, context):
326 Obj = context.active_object
328 if Obj.type == 'MESH':
329 Mode = False
330 if context.mode == 'EDIT_MESH':
331 Mode = not Mode
332 bpy.ops.object.editmode_toggle()
334 Data = Obj.data
336 if context.window_manager.key_shape:
337 if Obj.active_shape_key:
338 for Vert in Obj.active_shape_key.data:
339 Vert.keyframe_delete('co')
341 if context.window_manager.key_points:
342 for Vert in Data.vertices:
343 Vert.keyframe_delete('co')
345 if context.window_manager.key_bevel:
346 for Edge in Data.edges:
347 Edge.keyframe_delete('bevel_weight')
349 if context.window_manager.key_crease:
350 for Edge in Data.edges:
351 Edge.keyframe_delete('crease')
353 if context.window_manager.key_vgroups:
354 for Vert in Data.vertices:
355 for Group in Vert.groups:
356 Group.keyframe_delete('weight')
358 if context.window_manager.key_uvs:
359 for UV in Data.uv_layers.active.data:
360 UV.keyframe_delete('uv')
362 if context.window_manager.key_vcols:
363 for VColLayer in Data.vertex_colors:
364 if VColLayer.active: # only delete in active VCol layer
365 for Data in VColLayer.data:
366 Data.keyframe_delete('color')
368 if Mode:
369 bpy.ops.object.editmode_toggle()
371 if Obj.type == 'LATTICE':
373 Mode = False
374 if context.mode != 'OBJECT':
375 Mode = not Mode
376 bpy.ops.object.editmode_toggle()
378 Data = Obj.data
380 if context.window_manager.key_shape:
381 if Obj.active_shape_key:
382 for Point in Obj.active_shape_key.data:
383 Point.keyframe_delete('co')
385 if context.window_manager.key_points:
386 for Point in Data.points:
387 Point.keyframe_delete('co_deform')
389 if Mode:
390 bpy.ops.object.editmode_toggle()
392 if Obj.type in {'CURVE', 'SURFACE'}:
393 Mode = False
394 if context.mode != 'OBJECT':
395 Mode = not Mode
396 bpy.ops.object.editmode_toggle()
398 Data = Obj.data
400 # run this outside the splines loop (only once)
401 if context.window_manager.key_shape:
402 if Obj.active_shape_key_index > 0:
403 for CV in Obj.active_shape_key.data:
404 CV.keyframe_delete('co')
405 try: # in case spline has no handles
406 CV.keyframe_delete('handle_left')
407 CV.keyframe_delete('handle_right')
408 except: pass
410 for Spline in Data.splines:
411 if Spline.type == 'BEZIER':
412 for CV in Spline.bezier_points:
413 if context.window_manager.key_points:
414 CV.keyframe_delete('co')
415 CV.keyframe_delete('handle_left')
416 CV.keyframe_delete('handle_right')
417 if context.window_manager.key_radius:
418 CV.keyframe_delete('radius')
419 if context.window_manager.key_tilt:
420 CV.keyframe_delete('tilt')
422 elif Spline.type == 'NURBS':
423 for CV in Spline.points:
424 if context.window_manager.key_points:
425 CV.keyframe_delete('co')
426 if context.window_manager.key_radius:
427 CV.keyframe_delete('radius')
428 if context.window_manager.key_tilt:
429 CV.keyframe_delete('tilt')
431 if Mode:
432 bpy.ops.object.editmode_toggle()
435 return {'FINISHED'}
438 class ANIM_OT_clear_animation_animall(bpy.types.Operator):
439 bl_label = 'Clear Animation'
440 bl_idname = 'anim.clear_animation_animall'
441 bl_description = 'Delete all keyframes for this object'
442 bl_options = {'REGISTER', 'UNDO'}
444 # on mouse up:
445 def invoke(self, context, event):
447 wm = context.window_manager
448 return wm.invoke_confirm(self, event)
451 def execute(op, context):
453 Data = context.active_object.data
454 Data.animation_data_clear()
456 return {'FINISHED'}
459 def register():
460 bpy.utils.register_module(__name__)
462 pass
464 def unregister():
465 bpy.utils.unregister_module(__name__)
467 pass
469 if __name__ == "__main__":
470 register()