Script - Delete Flatlining Keyframe Channels

Hey fellow Blender heads, I’m still in the beginning of learning scripting so any help would be appreciated. I’m working with AnimAll. It’s great, but the only problem is it creates a lot of unnecessary keyframes for vertices that don’t move. I’d like to clear all these away with the click of a button. So to sum it up.

-Find animation channels that don’t move from 0
-Delete them

If you don’t want to do it but have tips on how, I’d greatly appreciate it. Thanks, you guys are great!

What do you mean “don’t move from 0”? Frame 0?

I mean that the vertex doesn’t move in the x,y, or z direction but still has multiple keys for x,y,z (all 0,0,0)

This should do it:


import bpy

def main(context):
    cnt = 0
    obj = context.active_object
    action = obj.animation_data.action
    for i in range(len(action.fcurves)-1, -1, -1):
        fcurve = action.fcurves[i]
        z_check = [p.co[1] == 0 for p in fcurve.keyframe_points]
        if False not in z_check:
            action.fcurves.remove(fcurve)
            cnt += 1
    return cnt

class CleanAction(bpy.types.Operator):
    """"""
    bl_idname = "object.clean_action"
    bl_label = "Clean Action"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None 

    def execute(self, context):
        cnt = main(context)
        self.report({'INFO'}, repr(cnt) + ' fcurves removed.')
        context.scene.update()
        return {'FINISHED'}

def register():
    bpy.utils.register_class(CleanAction)

def unregister():
    bpy.utils.unregister_class(CleanAction)

if __name__ == "__main__":
    register()

# test call
bpy.ops.object.clean_action()



Wow, nice, ill give it a go right now!