2
$\begingroup$

I'm trying to write a script that creates a Pie menu, and I want the menu item on the [1] position (which calls another submenu) to be disabled whenever the current scene isn't "Some Scene".

I've tried doing

pie.menu("SOME_MT_Submenu", text='Some Submenu")
if context.scene.name != 'Some Scene':
    pie.enabled = False
pie.menu("MENU_MT_Item", text = 'Menu item #2')
pie.menu("MENU_MT_Item", text = 'Menu item #3')    
pie.menu("MENU_MT_Item", text = 'Menu item #4')
#and so on

...but it just disables the entire pie menu. I've also tried adding a @classmethod poll function on the Submenu, like;

class SOME_MT_Submenu(bpy.types.Menu)
    bl_label = "Some Submenu"

    @classmethod
    def poll(cls, context):
        return context.scene.name == 'Some Scene'
    def draw(self, context):
        layout = self.layout
        layout.operator("some.operator", text = "Some Operator")
        layout.operator("some.operator", text = "Some Operator")
        layout.operator("some.operator", text = "Some Operator")

but whenever I run the script the menu item still calls out the submenu. And I've also tried adding the poll function to the 'Some Operator' class itself, and it still doesn't work.

I want that menu item to be grayed out and not call out the submenu when I hover over it. Is there a way to do that?

$\endgroup$
0

1 Answer 1

1
$\begingroup$

In the end, I just decided to get rid of the menu item itself if it doesn't satisfy the condition:

layout = self.layout
pie = layout.menu_pie()
if context.scene.name != 'Some Scene':
    pie.split()
else:
    pie.menu('SOME_MT_Submenu', text = 'Some Submenu')
$\endgroup$
2
  • 2
    $\begingroup$ Since context is an argument of draw and poll etc methods, use context.scene rather than bpy.context.scene. $\endgroup$
    – batFINGER
    Apr 27, 2020 at 15:39
  • 1
    $\begingroup$ @batFINGER Thanks! I didn't realize that XD $\endgroup$
    – NumpyNoob
    Apr 28, 2020 at 3:44

You must log in to answer this question.

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