2010
10.22

Modifying Maya menus

I’ve gotten sick of it being such a pain to work with Maya’s built in right click menu’s, so I’ve been playing today with finding a good way to modify them. I wanted to do this without copying over the existing scripts included with Maya. I also wanted to enable some features that Maya’s menus are lacking: Icons in menus, and Inserting items at positions other than the end.

Here’s my progress so far:

I am just doing a few simple steps to get to this point:

  1. Overwrite Maya’s default popup menu with my own, which calls a python function instead
  2. From there, call Maya’s built-in function to create the menu
  3. Then, grab the list of QActions that make up the menu
  4. Copy them into a new QMenu
  5. Delete all the items off of the original Maya menu, causing it not to show (This is before it ever displays in the UI)
  6. Insert items, add icons to existing ones, etc.. (Also hook up signals/slots if need be)
  7. Show my new QMenu at the cursor
  8. Once it’s all done, run action.deleteLater() on all the actions (Otherwise Maya complains about non unique names later)

The trickiest menus to work with are going to be the 3d viewport ones, because they seem to hook into some functions that are not meant to be used. I had previously copied over the dagMenu script, and a few others to implement these tools, and I really don’t like doing it that way. I am thinking of using my selectFromScreen code to completely re-implement background and object right click menus. I am excited to see where all this goes, and what new tools I can come up with to take advantage of it.

Edit: Looks like Autodesk’s implementation of radial menu’s is not meant to be messed with, all my attempts so far to add or insert new widgets into a menu with radial menu set to True have failed miserably…

  1. Hi Nathan,

    This looks absolutely brilliant.
    I’ve been looking for a way to attach an icon to a menuItem, but my PyQt knowledge so far is very limited. Do you mind to share a code example of your technique?
    For example, what would be the simplest way replace the menuItem here with a QPopupMenu?

    w = cmds.window(menuBar = True)
    m = cmds.menu(p = w, l = ‘foo’)
    i = cmds.menuItem(p = m, l = ‘bar’)
    cmds.showWindow()

    Cheers,
    m

  2. Any luck getting menus to function property in the Maya menu bar? Still having issues over here 🙁

You must be logged in to post a comment.