Is there a way to move a keyframe using Python (change the frame at which the keyframe is set)?

The keyframe already exists. I need to access it and move it, with the script.


This is not hard:

bpy.data.actions[aname].fcurves[i].keyframe_points[j].co[0] = fr1

The tricky part is picking the right fcurve[i] and keyframe_points[j] if there are more than one. You'll have to check fcurve[i].data_path and (if it's a vector data_path like location or rotation*) fcurve[i].array_index to make sure you're altering the right fcurve.

  • 4
    $\begingroup$ You can also access co[0] and co[1] like co.x (frame) and co.y (value). The action associated with an object is accessible via Object.animation_data.action. Note that both animation_data and action can be None. $\endgroup$
    – CodeManX
    Jan 28 '15 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.