Maya – Custom menu is not showing on menu bar

Question:

I am trying to build a custom menu in maya.

google groups has this code and it shows that it works but when i try it does not show in menu bar for me. I have tried for hours. What else is required for it to show in menu.
IOW why does it not show in maya menu bar.

https://groups.google.com/g/python_inside_maya/c/XqM7Rkm2kOE

import pymel.core as pm

# Name of the global variable for the Maya window
MainMayaWindow = pm.language.melGlobals['gMainWindow'] 

# Build a menu and parent underthe Maya Window
customMenu = pm.menu('Custom Menu', parent=MainMayaWindow)
# Build a menu item and parent under the 'customMenu'
pm.menuItem(label="menu item 'hihi'", command="print 'hihi'", parent=customMenu)

edit :
when querying menus it does show it in the list

maya_main_window = mel.eval("$tmpVar = $gMainWindow")

menus = cmds.window(maya_main_window, query=True, menuArray=True)
for menu in menus:
    print menu
Asked By: nish

||

Answers:

It works

I’m using Maya 2020 running on macOS Monterey. Your code works fine. Here’s a screenshot:

enter image description here

import pymel.core as pm

MainMayaWindow = pm.language.melGlobals['gMainWindow']
customMenu = pm.menu('Custom Menu', parent=MainMayaWindow)
pm.menuItem(l="menu item 'hihi'", command="print 'hihi'", parent=customMenu)

If it doesn’t work

If you can’t create that menu, the problem is, your module might be corrupted. I think the best two things you can do about it – to reinstall it, or just use maya.cmds instead of PyMel or OpenMaya.

The main reason not to use PyMel – because it’s too slow. The main reason not to use OpenMaya – because there’s so much boiler plate code. Watch this video to find out what cons and pros PyMel module has.

Answered By: Andy Jazz
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.