clear keyframe of specific property of selected object
import bpy
def clear_keyframe(obj, data_path, ind=None):
try:
fcs = obj.animation_data.action.fcurves
if ind is None:
fc = fcs.find(f'{data_path}')
else:
fc = fcs.find(f'{data_path}', index=ind)
fcs.remove(fc)
print(f"{obj} {fcsfc} removed")
except:
if hasattr(obj, "name"):
print(f"{obj.name} fcurve remove fail")
else:
print(f"object fcurve remove fail")
for obj in bpy.context.selected_objects:
clear_keyframe(obj, "location", 0)
clear_keyframe(obj, "location", 1)
clear_keyframe(obj, "location", 2)
clear all keyframes of all level one properties (not include modifiers, shape key, ...) of selected object
import bpy
def clear_keyframe(obj, data_path, ind=None):
try:
fcs = obj.animation_data.action.fcurves
if ind is None:
fc = fcs.find(f'{data_path}')
else:
fc = fcs.find(f'{data_path}', index=ind)
fcs.remove(fc)
except: pass
for obj in bpy.context.selected_objects:
props = obj.bl_rna.properties
for prop in props:
array_length = getattr(prop, "array_length", None)
if array_length is not None and array_length > 1:
for r in range(array_length):
clear_keyframe(obj, prop.identifier, r)
else:
clear_keyframe(obj, prop.identifier)