2
$\begingroup$

I'm making an Iron Man helmet. I have rigged it and animated it. I want to make a custom UI panel to control the animated action. I'm completely new to scripting and I have no idea how to do it. Basically I want the action to be activated when the button in the panel is pressed.

Can anyone help?

$\endgroup$
  • $\begingroup$ Depending on what your using it for, it would be easier to do it in the game engine. $\endgroup$ – cmomoney Jan 18 '17 at 17:01
1
$\begingroup$

With this code you can trigger an action (adding a plane into Scene) with a Button in 'UI Panel' using Python.

import bpy
from random import randint

class UIPanel(bpy.types.Panel):
    bl_label = "This is UI panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"

    def draw(self, context):
        self.layout.operator("object.plane", text='click to add', icon="BLENDER")

class OBJECT_OT_AddButton(bpy.types.Operator):
    bl_idname = "object.plane"
    bl_label = "Add a plane to the scene"

    def execute(self, context):
        print ("This is a test print statement")
        x = randint(0,10)
        y = randint(0,10)
        bpy.ops.mesh.primitive_plane_add(location=(x,y,0))
        return {'FINISHED'}

bpy.utils.register_module(__name__)
$\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.