3
$\begingroup$

Say I have a property set on a scene, like so:

bpy.types.Scene.is_enabled = bpy.props.BoolProperty(default=False)

Then I've got a panel like the following:

class SomePanel(bpy.types.Panel):
    bl_idname      = "the_panel"
    bl_label       = "Panel with some controls"
    bl_space_type  = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context     = "object"

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

        layout.prop(scene, "is_enabled")

Now what I would like to do is to render an operator or some other control in the panel only if the property of scene is_enabled is set to true?

How can I do that?

$\endgroup$

1 Answer 1

4
$\begingroup$

The solution was so trivial I didn't expect it to be. It's a matter of simply adding a conditional to the panel draw function:

class SomePanel(bpy.types.Panel):
    bl_idname      = "the_panel"
    bl_label       = "Panel with some controls"
    bl_space_type  = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context     = "object"

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

        layout.prop(scene, "is_enabled")

        if scene.is_enabled:
            layout.operator("object.select_random") # As an example.
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .