Monday, August 22, 2011

Right-click Menu in Maya using Python

This might be a little obscure but thought I would throw this out there for anyone who searches this with Google. I know it was frustrating to find any kind of real resource on the subject so here it is. You can add a right-click pop-up menu to pretty much any UI element with Mel/Python in Maya. Here is a link to the docs about this menu:

Take a look at the example. Not too informative but basically all you need is a parent to attach the menu to and set the button to be the RMB, and you are done!


import maya.cmds as cmds

win = cmds.window()
btn = cmds.button(l='Click Me')
popup = cmds.popupMenu(parent=btn, ctl=False, button=3)
item1 = cmds.menuItem(l='Item1', c='whatever and')
item2 = cmds.menutItem(l='Item2', c='whatever')


and there you go! That's really all there is to it.

No comments:

Post a Comment