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?

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

1 Answer 1


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)
        return {'FINISHED'}


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.