tleedz
(tleedz)
July 28, 2015, 6:09am
1
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!
-T
CoDEmanX
(CoDEmanX)
July 29, 2015, 5:15pm
2
Maybe something like this:
import bpy
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
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", bpy.data, "actions")
def execute(self, context):
self.report({'INFO'}, self.action_name)
scene = context.scene
action = bpy.data.actions.get(self.action_name)
if action is None:
return {'CANCELLED'}
for ob in context.selected_editable_objects:
if ob.type != 'MESH':
continue
if ob.animation_data is None:
ob.animation_data_create()
tracks = ob.animation_data.nla_tracks
track = tracks.new()
track.strips.new(action.name, scene.frame_current, action)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call (with CubeAction pre-selected
bpy.ops.object.simple_operator('INVOKE_DEFAULT', action_name="CubeAction")