I need to clear keyframes from the active shapekey using python. I got this far, this is removing the current keyframe on the active shapekey, but got no clue how to remove all of the keyframes.
def clear_shape_key_keyframes_selected():
obj = bpy.context.active_object
shapekeys = obj.data.shape_keys.key_blocks
active_shapekey = shapekeys[obj.active_shape_key_index]
active_shapekey_name = active_shapekey.name
try:
obj.data.shape_keys.keyframe_delete(f"key_blocks[\"{active_shapekey_name}\"].value")
except RuntimeError:
print("Shapekey has no animation data to delete")
other things I tried:
This does work, but deletes keyframes on all the shapekeys:
def clear_shape_key_keyframes():
obj = bpy.context.active_object
shape_keys = obj.data.shape_keys
key_blocks = obj.data.shape_keys.key_blocks
active_shapekey = key_blocks[obj.active_shape_key_index]
shape_keys.animation_data_clear()
However, this does not work, and gives me the:
error "AttributeError: 'ShapeKey' object has no attribute 'animation_data_clear'"
def clear_shape_key_keyframes():
obj = bpy.context.active_object
shape_keys = obj.data.shape_keys
key_blocks = obj.data.shape_keys.key_blocks
active_shapekey = key_blocks[obj.active_shape_key_index]
active_shapekey.animation_data_clear()
Which is really odd since both seem to be shapekey objects.