Maya print menus
Autodesk Maya supports both Qt & build-in functions to make menus.
the build-in functions are simpler, see
unimenu uses the build-in methods
Maya Python code to list maya menus.
def find_menu(name):
gMainWindow = maya.mel.eval('$temp=$gMainWindow')
# get all the menus that are children of the main menu
mainWindowMenus = maya.cmds.window(gMainWindow, query=True, menuArray=True)
for menu in mainWindowMenus:
print(menu)
if menu.lower() == name.lower():
return menu
interestingÂś
Slack
Bob Whiteâ
Depends on what and where.
But if specifically trying to query items in the default menus you usually need to execute their on-first-open command (canât remember the actual name for it)
Bob White
But basically all menuâs are empty at startup until you click around
Hâ
once i have a menu or menu item itâs easy to get the children.
but how can i get that first menuitem
. use case is add a submenu to an existing menu in code
Bob White
for some reason I thought you could useâpostMenuCommand
âto query the command and then run it. But it doesnât have the query flag in the documentation.
I donât have a copy of Maya in front of me, but you can probably dig the command out of one of the mel
files in maya, and basically query the menu, if it doesnât have children yet, run the command, and then work with it.â
Travis Evashkevich!
I wishâQMenu
âhad an easy way to get the children from it, as you can just get the QMainWindow
of Maya, get menuBar
and that gives you all the menus from the looks of it, but yeah finding the children is a pita..
Bob Whiteâ
Children donât exist yet, at least not until youâve opened them once.
Mayaâs startup would be all the slower if it didnât defer some of those
Bob White
Plus plugins loading etcâŚ
Shea Richardson
If it is a qmenu
there is .actions
And if the action has a menu, itâs action.menu
Or something like that?
Our menus are pure Qt
So that is how we access menu items
Travis Evashkevich
Ah thatâs interesting, I hadnât thought about .actions being the .children
- great ref for maya menu code
more code samples
get all maya menu commands, source
from maya import cmds, mel
menu_items_and_their_commands = {}
for menu in cmds.window(mel.eval('$temp1=$gMainWindow'), q=True, ma=True):
menu_items_and_their_commands[menu] = {}
for item in cmds.menu(menu, q=True, ia=True) or []:
menu_items_and_their_commands[menu][item] = cmds.menuItem(item, q=True, c=True)