This code work for time range. I need to change this and use script for delete selection keyframes. This help me work quickly, and delete key without question any time “delete keyframes”.
If anyone can help?
Thank you!
class DELETE_KEYFRAMES_RANGE(bpy.types.Operator):
bl_idname = "pose.delete_keyframes"
bl_label = "Delete Keyframes"
bl_options = {'REGISTER', 'UNDO'}
bl_description = "Delete all keyframes for selected bones in a time range"
@classmethod
def poll(cls, context):
obj = bpy.context.object
return obj.type == 'ARMATURE' and obj.mode == 'POSE'
def execute(self, context):
wm = bpy.context.window_manager
arm = bpy.context.object
act = arm.animation_data.action
delete = []
# get selected bones names
sel = [b.name for b in arm.data.bones if b.select]
# get bone names from fcurve data_path
for fcu in act.fcurves:
name = fcu.data_path.split(sep='"', maxsplit=2)[1]
# check if bone is selected and got keyframes in range
if name in sel:
for kp in fcu.keyframe_points:
if wm.del_range_start <= kp.co[0] <= wm.del_range_end:
delete.append((fcu.data_path, kp.co[0]))
# delete keyframes
for kp in delete:
arm.keyframe_delete(kp[0], index=-1, frame=kp[1])
context.scene.frame_set(context.scene.frame_current)
return {'FINISHED'}