Scripting Question "bpy.ops.nla.actionclip_add(action='CubeAction .001 ')"

I am by no means a programmer, but would love some guidance.

I would like to create a button that runs the below script when pressed. Basically, I need it to add “CubeAciton.001” to whatever mesh I have selected.

bpy.ops.nla.actionclip_add(action=‘CubeAction.001’ )

Thanks in advance!


Maybe something like this:

import bpy

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    action_name = bpy.props.StringProperty(name="Action")

    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)
    def draw(self, context):
        self.layout.prop_search(self, "action_name",, "actions")

    def execute(self, context):{'INFO'}, self.action_name)
        scene = context.scene
        action =
        if action is None:
            return {'CANCELLED'}
        for ob in context.selected_editable_objects:
            if ob.type != 'MESH':
            if ob.animation_data is None:
            tracks = ob.animation_data.nla_tracks
            track =
  , scene.frame_current, action)
        return {'FINISHED'}

def register():

def unregister():

if __name__ == "__main__":

    # test call (with CubeAction pre-selected
    bpy.ops.object.simple_operator('INVOKE_DEFAULT', action_name="CubeAction")