3
$\begingroup$

I have made a custom panel in Blender and I would like to have 3 buttons. Currently I've taken the render button and just copied and pasted that into my panel and changed the name of it just for a place holder. How can I make my own button, like how I would make my own checkbox etc. Also, it's currently one of these kinds of buttons: enter image description here

How and also make it this kind of button: enter image description here

$\endgroup$
7
$\begingroup$

Panels can't have their own properties defined inside the Panel's class (by design), this means you must register properties either as part of the Scene or as part of the Object class, or as part of a higher level PropertyGroup. A group keeps your properties organized and avoids potential naming conflicts between other add-ons.

Here's a small snippet that creates a Panel, and registers a property group with as many properties as you might need. The update function called by the enum is where you could execute code.

This is one way to do that, scavenge what you need from this:

import bpy

def update_after_enum(self, context):
    print('self.my_enum ---->', self.my_enum)


class IgnitProperties(bpy.types.PropertyGroup):
    my_enum = bpy.props.EnumProperty(
        name = "My options",
        description = "My enum description",
        items = [
            ("Silver" , "Silver" , "Description..."),
            ("Gold", "Gold", "other description"),
            ("Space Grey", "Space Grey", "Some other description")            
        ],
        update=update_after_enum
    )
    # my_string = bpy.props.StringProperty()
    # my_integer = bpy.props.IntProperty()


class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "IG Layout Demo"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout
        scene = context.scene
        row = layout.row()
        row.prop(scene.ignit_panel, "my_enum", expand=True)


def register():
    bpy.utils.register_module(__name__)
    bpy.types.Scene.ignit_panel = bpy.props.PointerProperty(type=IgnitProperties)


def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.Scene.ignit_panel


if __name__ == "__main__":
    register()

enter image description here

If you want bigger buttons a different approach is needed.

$\endgroup$
  • $\begingroup$ Wonderful answer! Are there any guidelines for the bl_idname of the Panel? The official documentation about bl_idname there reads a bit like an unfinished sentence and didn't really answer it for me. $\endgroup$ – Ray Feb 17 '16 at 17:58

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.