3
$\begingroup$

I want to create a own UI for a add-on which I am writing. The user should have the ability to do different things with this add-on. For example he can choose a cube or a pyramid. If cube or pyramid is choosen the ui will change. Some fields should be hidden and some should be visible.

Okay, first step: Create radio buttons. And now I am stuck :/

As far as I know I need a EnumProperty, which has the attribute items. Items has all the "values" the radio button can have.

Sadly it's not working for me.

I did this:

    def draw(self, context):
        layout = self.layout

        obj_types_enum = ('0','a','a')
        obj_type = bpy.props.EnumProperty(items = obj_types_enum)

        layout.label("Select original form")

        col = layout.column()

        col.prop(self, 'obj_type')

Any advice?

$\endgroup$
0
4
$\begingroup$

This is how you do it:

# This is how you make a static enum prop for the scene
enum_items = (('0','Cube',''),('1','Pyramid',''))
bpy.types.Scene.obj_type = bpy.props.EnumProperty(items = enum_items)

# This is how you display it in panel
def draw(self, context):
    layout = self.layout
    layout.label(text="Select Original Form")

    layout.prop(context.scene, 'obj_type', expand=True)
$\endgroup$
3
  • $\begingroup$ Uhu… didn’t even saw that :( $\endgroup$ – mont29 May 5 '15 at 10:03
  • $\begingroup$ Thanks! Could you also say me how I can react to these buttons? For example when Cube is pressed execute a method. I could do this with a own button(bpy.types.Operator) and the execute(self, context) method. But I don't have them. $\endgroup$ – Hamburml May 5 '15 at 10:23
  • 1
    $\begingroup$ @Michael You can specify an update function for your property, it will be run everytime the property changes. The answer how is here: blender.stackexchange.com/questions/23399/… $\endgroup$ – Jaroslav Jerryno Novotny May 5 '15 at 10:43
2
$\begingroup$

You can replace col.prop(self, 'obj_type') by col.prop(self, 'obj_type', expand=True). This won’t give you real radio buttons, but each enum option will have its own toggle button, instead of having a single drop-down list.

Note you can have all your options in a row or in a column, depending on the direction of the current layout (row() and split() layouts are horizontal, column() and box() are vertical…).

There is no way to get real radio buttons currently in Blender py UI API, afaik (and you won’t find any in current interface).

$\endgroup$
2
  • $\begingroup$ Well you can make radio buttons with bool properties and with 'RADIOBUT_OFF' and 'RADIOBUT_ON' icons and handle their switching with code ;) $\endgroup$ – Jaroslav Jerryno Novotny May 5 '15 at 10:14
  • $\begingroup$ @Jerryno That’s what I call bad hacking! :P $\endgroup$ – mont29 May 5 '15 at 10:34

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.