# Contextually grey out panel element in python 2.8

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.label(text="Dynamics:")
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.label(text="Dynamics:")
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')

• sub = col.row() would suffice. – batFINGER Dec 15 '19 at 6:01
• Ah, Thanks very much. You've been exceptionally helpful. I'm getting a massive amount accomplished due to your very timely help. ^_^ – Mike Dec 15 '19 at 7:13

Set UILayout.enabled

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):

@classmethod
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.

• 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. ~_~ – Mike Dec 14 '19 at 7:41
• 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. – Mike Dec 14 '19 at 9:30
• 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. ^_^ – Mike Dec 14 '19 at 9:36