0
$\begingroup$

I was wondering if there's a way to delete all keyframes on the locked channels in items panel or Bone Properties > Transform panel? As one can do with right mouse click and selecting delete kleyframes or delete single keyframe The code that performs this operation is:

bpy.ops.anim.keyframe_delete_button(all=True)

or I guess if multiple keyframes:

bpy.ops.anim.keyframe_clear_button()

Whatever I tried I had 0 luck.

Basically I’d need the code to check if selected pose bone has any locked channels in these panels and if it does and if those channels are still keyframed, to delete all the keyframes from those channels.

Is this possible?

$\endgroup$

1 Answer 1

0
$\begingroup$

I found a way to do it. I don't know if it's the best way or the right way but it works for what I need at the moment. Here's what I got.

def execute (self, context):
    pose_bone = bpy.context.active_pose_bone
    bone_name = pose_bone.name
    data_path_sca = "scale"

    start_frame = bpy.context.scene.frame_start
    end_frame = bpy.context.scene.frame_end
    frame_range = range(start_frame, end_frame + 1) # +1 to include the end frame

    if all(pose_bone.lock_scale):
        for frame in frame_range:
            pose_bone.keyframe_delete(data_path_sca, index=-1, frame=frame, group="{}".format(bone_name), options=set())
    if not all(pose_bone.lock_scale):
        if pose_bone.lock_scale[0] == True:
            for frame in frame_range:
                pose_bone.keyframe_delete(data_path_sca, index=0, frame=frame, group="{}".format(bone_name), options=set())
        if pose_bone.lock_scale[1] == True:
            for frame in frame_range:
                pose_bone.keyframe_delete(data_path_sca, index=1, frame=frame, group="{}".format(bone_name), options=set())
        if pose_bone.lock_scale[2] == True:
            for frame in frame_range:
                pose_bone.keyframe_delete(data_path_sca, index=2, frame=frame, group="{}".format(bone_name), options=set())
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .