UN keyframe_insert?

Hi All,

Is there a simple way to remove existing keyframes for a value?

Say I have added keyframes like so…

temp_ob.keyframe_insert(data_path='hide', frame=(end_frame-1))

Now I run my code again, but I want to remove the previous keyframes before I add replacement keyframes.

There is keyframe_delete, but by the time I run my code again, parameters could have changed and new data could be targeting new frames.

How do I just throw away the existing f-curve?
.
.
.
This seems to work.


def eraseAllKeyframes(passedOB = None):
    if passedOB != None:
        ad = passedOB.animation_data
        if ad != None:
            passedOB.animation_data_clear()

do you wanna actually do keyframe_replace()?

like adding points to fcurve in a certain range, but if any points already exist in that range, remove them?

I basically need a blank slate because the new keyframes might not be in the same location, in time, that the old ones were. I was quite happy to see that animation_data_clear actually removes keyframes on modifiers and constraints as well as typical object values.

well if you wanna get rid of an entire fcurve, do:

C.object.animation_data.action.fcurves.remove(your_fcurve)

or just truncate the keyframe points:

kp = C.object.animation_data.action.fcurves[0].keyframe_points
for p in reversed(kp):
    kp.remove(p)

Thanks, those might be better options when speed is a concern. But one call to remove multiple keyframes on an object and animated constraints is hard to pass up.

ideasman mentioned somewhere, that an extra option for keyframe_insert to replace an existing fcurve point should be implemented, but not sure how useful that would be… I’d rather like to have a keyframe_clear_range(), one call, multiple keyframe points removed.