0
$\begingroup$

I am looking for a way to copy all keyframes from Action A to Action B with time offset X using python.

Any ideas?

$\endgroup$
2
$\begingroup$

Here is a script that copies actionA (hardcoded to "CubeAction", change to suit) to actionB and adds a frame offset to each key.

import bpy
# change how action is picked
# actionA = bpy.context.object.animation_data.action
actionA = bpy.data.actions.get("CubeAction")
if actionA is not None:
    # copy the action
    actionB = actionA.copy()
    offset = 10 # frames
    # iter thru fcurves and move keyframes by offset
    for fc in actionB.fcurves:
        for kf in fc.keyframe_points:
            kf.co.x += offset

Note this can also be done pretty simply in the NLA, by moving an action strip to the desired frame start. This way you can keep all your actions as starting at frame 1.

$\endgroup$

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.