Disabling a menu item

Disabling a menu item

ckingT5S5B
Participant Participant
780 Views
3 Replies
Message 1 of 4

Disabling a menu item

ckingT5S5B
Participant
Participant

Hi, 

 

I am writing a python script that adds menu items. I would like to be able to disable my menu items with they are not applicable. 

 

I have added a postMenuCommand to my menu. In that command I am calling something like:

 

cmds.menuItem(name, enable=False)

 

Where name is that string that was returned from cmds.menuItem when the item was first created.

 

It look to me like attempting to disable a item after it is created doesn't work. Is there a better way to do this?

 

Thanks,

Chris King

Spire Animation Studios

0 Likes
Accepted solutions (1)
781 Views
3 Replies
Replies (3)
Message 2 of 4

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

If you want to edit an existing UI or menu Item, you need to use the edit flag (e), because those kind of commands are per default in creation mode, so the script you are running tries to add another menu item with the same name.

This should work:

cmds.menuItem(name,e= True, enable=False)

 

I hope it helps!

0 Likes
Message 3 of 4

ckingT5S5B
Participant
Participant

Wouldn't it be awesome if this was documented. 

There is no mention of a edit flag here:  https://help.autodesk.com/view/MAYAUL/2023/ENU/index.html?contextId=COMMANDSPYTHON-INDEX

0 Likes
Message 4 of 4

Kahylan
Advisor
Advisor

The E in the Red Square on the right side of some flags means that a flag is available in edit mode.

 

The flags create (c),edit (e) and query (q) are never mentioned in the documentation, because basically every command has them, but it is more useful on some than on others. They are indicated for specific flag with the colored letters.

 

But yeah, it also took me a while of maya programming to realise that.

0 Likes