Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Blank Keyframe Insertion Addon for Blender 2.70+
- # Copyright (C) 2014 Morshidul Chowdhury
- # 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
- # MERCHANTABILITY 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/>.
- bl_info = {
- "name": "Insert Blank Keyframes",
- "author": "Morshidul Chowdhury (iPLEOMAX)",
- "version": (1, 0),
- "blender": (2, 7, 0),
- "location": "Graph Editor > Blank Keyframes",
- "description": "Insert blank keyframes starting from current frame",
- "warning": "",
- "category": "Animation"
- }
- #Addon created as a response to this thread:
- #http://blenderartists.org/forum/showthread.php?337331-Add-on-script-for-frame-insertion&p=2650614
- import bpy
- from mathutils import Vector
- from bpy.types import Header
- from bpy.props import IntProperty
- bpy.types.Scene.blank_keyframes = IntProperty(name = "Blank Keyframes", default = 1, min = 1, max = 1000)
- class InsertBlankKeyframe(bpy.types.Operator):
- bl_idname = "anim.keyframe_insert_blank"
- bl_label = "Insert"
- bl_description = "Insert blank keyframes at current frame"
- def execute(self, context):
- object = context.active_object
- if not object: return {'CANCELLED'}
- scene = context.scene
- if not scene: return {'CANCELLED'}
- bpy.ops.graph.keyframe_insert(type='ALL')
- frame = bpy.context.scene.frame_current
- blanks = context.scene.blank_keyframes
- values = {}
- for fc in object.animation_data.action.fcurves:
- for kp in fc.keyframe_points:
- if kp.co[0] >= frame:
- if kp.co[0] == frame:
- values[fc.data_path + str(fc.array_index)] = kp.co[1]
- kp.select_control_point = True
- kp.select_left_handle = True
- kp.select_right_handle = True
- else:
- kp.select_control_point = False
- kp.select_left_handle = False
- kp.select_right_handle = False
- bpy.ops.transform.translate(value=(blanks, 0, 0))
- bpy.context.scene.frame_current = frame
- bpy.ops.graph.keyframe_insert(type='ALL')
- for fc in object.animation_data.action.fcurves:
- index = fc.data_path + str(fc.array_index)
- if index in values:
- for kp in fc.keyframe_points:
- if kp.co[0] == frame:
- kp.handle_left_type = 'FREE'
- kp.handle_right_type = 'FREE'
- #kp.handle_right[1] = kp.co[1]
- kp.co[1] = values[index]
- kp.handle_right[1] = kp.co[1]
- if kp.co[0] == frame + blanks:
- kp.handle_left_type = 'FREE'
- kp.handle_right_type = 'FREE'
- kp.handle_left[1] = kp.co[1]
- bpy.ops.transform.translate()
- return {'FINISHED'}
- class GRAPH_HT_header_custom(Header):
- bl_space_type = 'GRAPH_EDITOR'
- def draw(self, context):
- layout = self.layout
- row = layout.row(align=True)
- row.prop(context.scene, 'blank_keyframes')
- row.operator(InsertBlankKeyframe.bl_idname)
- def register():
- bpy.utils.register_module(__name__)
- def unregister():
- bpy.utils.unregister_module(__name__)
- if __name__ == "__main__":
- register()
Advertisement
Add Comment
Please, Sign In to add comment