I cam up with this solution MainMayaWindow = pm.language.melGlobals['gMainWindow'] # create a menu item pm.menu('Custom Menu', parent=MainMayaWindow)
# then, get the menus and menus = pm.window( MainMayaWindow, q=1, menuArray=1) nums = len(menus) #nums = pm.window(MainMayaWindow, q=1, numberOfMenus=1) # this gives a different length than len(menus) so is not used... targetMenuLabel = "Custom Menu" menuItemName = '' index = 0 for item in menus: itemLabel = pm.menu(item, q=1, l=1) if itemLabel == targetMenuLabel: print(f'item index: {index}') print(f'item label: {menus[index]}') menuItemName = item break index+=1 # if there's a match, delete the menu item if(menuItemName): pm.deleteUI(menuItemName) tisdag 7 februari 2023 kl. 01:00:59 UTC+1 skrev Dag Isaksson: > I've been playing around with adding menus to the UI and I've looked into > doing it with maya.cmds, pymel and the Qt module itself. > This is not really a major issue, but I'd still like to understand how i > could delete a menu from Maya's main window bar(File, Edit, Select, Create, > etc.) by using the label name. > I created a menu item of my own and accidentally forgot to give it a name > and to store the return in a variable. All it has is a label. > Besides using the Qt module I'm not sure how to get the menuitems from > either PyMEL or maya.cmds. > > For instance: > from PySide2 import QtWidgets, QtCore > import shiboken2 > import maya.OpenMayaUI as omui > > winPtr = omui.MQtUtil.mainWindow() > mayaWindow = shiboken2.wrapInstance(int(winPtr), QtWidgets.QWidget) > > #we got the MayaWindow pointer, now let's grab the QMenubar > menubar = "" > for child in mayaWindow.children(): > if isinstance(child, PySide2.QtWidgets.QMenuBar): > menubar = child > > itemToDel = '' > #then from this main menu bar, get the TopMenu Titles > for topmenu in menubar.actions(): > if topmenu.isVisible(): > if topmenu.text()=='My Menu': > itemToDel = topmenu > break > > So now I have the menu item in a QAction object. But unsure how I can use > that to delete it. > > Also is it good procedure to delete the submenus before deleting the main > menu item? > Does it matter? > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f77fae3c-f5d1-4441-bb00-725a0a139b1an%40googlegroups.com.