I have a panel with split column. In the 2nd row is 3 boolean variables. I want to grey out the 2nd and 3rd option by default. I want the 2nd to be changeable if 1st is true, and 3rd to be changeable if both 1 and two are true. I've read something about "poll()" but not how to actually use it, or set conditions. Physics should only be enablable if singleMesh, and destructable only if physics enabled.

    # Create two columns, by using a split layout.
    split = layout.split()

    # First column
    col = split.column()
    col.label(text="Building Size:")
    col.prop(bpy.context.scene.user_vars, 'buildingHeight')
    col.prop(bpy.context.scene.user_vars, 'buildingWidth')
    col.prop(bpy.context.scene.user_vars, 'buildingDepth')

    # Second column, aligned
    col = split.column()
    col.prop(bpy.context.scene.user_vars, 'singleMesh')
    col.prop(bpy.context.scene.user_vars, 'enablePhysics')
    col.prop(bpy.context.scene.user_vars, 'destructable_Building')

#EDIT This is what the specific solution to my example looks like.
col = split.column()
col.prop(vars, 'singleMesh')
sub = col.row()
sub.enabled = vars.singleMesh
sub.prop(vars, 'enablePhysics')
sub = col.row()
sub.enabled = vars.enablePhysics
sub.prop(vars, 'destructable_Building')
  • 1
    $\begingroup$ sub = col.row() would suffice. $\endgroup$ – batFINGER Dec 15 '19 at 6:01
  • $\begingroup$ Ah, Thanks very much. You've been exceptionally helpful. I'm getting a massive amount accomplished due to your very timely help. ^_^ $\endgroup$ – Mike Dec 15 '19 at 7:13

Set UILayout.enabled


When false, this (sub)layout is grayed out

eg enable subrow in a row if context object has rigid body settings

row = self.layout.row()
sub = row.row()
sub.enabled = context.object.rigidbody is not None
sub.prop(foo, "bar")

Note that context is passed as an argument to draw methods. Get out of the, IMO, bad habit of always addressing from bpy ie if in a draw method def draw(self, context): use context in method code not bpy.context.

The poll method works on a per Panel or Menu or Operator class et al case. The following will ensure FooPanel only draws when there is a context object.

class FooPanel(bpy.types.Panel):

    def poll(cls, context):
        return context.object is not None

panels that don't poll don't show. Operators are disabled if in layout but don't poll. It is important to have a poll method in most cases.

Re versions, both layout enabled and poll method are avalable in all versions >= 2.50.

  • $\begingroup$ From my understanding, the first enables/disables an entire row, which isn't quite what I'm looking for. I want to grey out just 1 property of a column. I don't understand, at all, how to add/alter what you wrote to fit the code I already have. Nor do I understand "Get out of the, IMO, bad habit of always addressing from bpy" Sorry, I'm a C# guy, python looks bassackwards to me. ~_~ $\endgroup$ – Mike Dec 14 '19 at 7:41
  • $\begingroup$ Ah, I think you misunderstand. I have a column. I want the 2nd button in 2nd column to be greyed out until first button in that column is selected. And the 3rd button should be greyed out until both the first and 2nd button are checked. "context.object.rigidbody" isn't valid in this context. $\endgroup$ – Mike Dec 14 '19 at 9:30
  • $\begingroup$ Thanks, not quite right, but close enough to where I was able to alter it to get it to work. Thanks a TON! You've helped me on several problems already. ^_^ $\endgroup$ – Mike Dec 14 '19 at 9:36

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.