1
$\begingroup$

I'm trying to make a different actions for the character. Some actions have the same key frames of others, then I have to copy and then paste to the current action, that takes me much of time.

So, I want to make a python script to copy all of the key frames from a special action, and then append them at the end of current selected action.

This is what I have done

import bpy


def main(context):
    actionWillBePasted = bpy.data.actions["first_action"]
    ob = bpy.context.object
    targetActionName = (ob.animation_data.action.name if ob.animation_data is not None and ob.animation_data.action is not None else "")
    if targetActionName != "":
        targetAction = bpy.data.actions[targetActionName]
        if actionWillBePasted is not None and targetAction is not None:
            #TODO 1 Copy all of actionWillBePasted action's key frames
            #TODO 2 Append the copied iframes to the targetAction

class AppendTheFirstAction(bpy.types.Operator):
    """Append first action key frames to the current selected"""
    bl_idname = "object.append_first_action"
    bl_label = "Add the first action to the current one"

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

    def execute(self, context):
        main(context)
        return {'FINISHED'}


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


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


if __name__ == "__main__":
    register()

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

Please help me to complete TODO 1 and TODO 2 purpose. Thanks,

$\endgroup$
  • $\begingroup$ this may help: docs.blender.org/api/2.83/… $\endgroup$ – Shantanu Aryan Oct 29 '20 at 12:38
  • $\begingroup$ Hi @ShantanuAryan the issue is I can't select the keyframes by using python script $\endgroup$ – Titi Nov 1 '20 at 7:44

Your Answer

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

Browse other questions tagged or ask your own question.