How to remove only rotation keyframes from current action with Python? Or location keyframes? Or scale? Is it passible?
Similarly to this related (possible duplicate) question. Example script removes all Location, Rotation and Scale fcurves from an action. It tests the
FCurve.data_path against the keyframe type list
["location", "rotation", "scale"]. Note
"rotation" will match
"rotation_quaternion" etc, which will be the actual datapath (as there is no
Avoided using the
FCurves.find method with a list comprehension, and used
pop to avoid possibly referencing a removed fcurve later.
import bpy context = bpy.context ob = context.object ad = ob.animation_data if ad: action = ad.action if action: remove_types = ["location", "scale", "rotation"] # select all that have datapath above fcurves = [fc for fc in action.fcurves for type in remove_types if fc.data_path.startswith(type) ] # remove fcurves while(fcurves): fc = fcurves.pop() action.fcurves.remove(fc)
To remove only y axis Loc, Rot and Scale also test for the
Fcurve.array_index property which is 0, 1, 2 for x, y, z respectively.
fcurves = [fc for fc in action.fcurves for type in remove_types if fc.data_path.startswith(type) and fc.array_index == 1 ]