Python maya.cmds.menu() Examples
The following are 30
code examples of maya.cmds.menu().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: ml_utilities.py From ml_tools with MIT License | 7 votes |
def buttonWithPopup(self, label=None, command=None, annotation='', shelfLabel='', shelfIcon='render_useBackground', readUI_toArgs={}): ''' Create a button and attach a popup menu to a control with options to create a shelf button or a hotkey. The argCommand should return a kwargs dictionary that can be used as args for the main command. ''' if self.icon: shelfIcon = self.icon if annotation and not annotation.endswith('.'): annotation+='.' button = mc.button(label=label, command=command, annotation=annotation+' Or right click for more options.') mc.popupMenu() self.shelfMenuItem(command=command, annotation=annotation, shelfLabel=shelfLabel, shelfIcon=shelfIcon) self.hotkeyMenuItem(command=command, annotation=annotation) return button
Example #2
Source File: pipeline.py From core with MIT License | 6 votes |
def install(): """Install Maya-specific functionality of avalon-core. This function is called automatically on calling `api.install(maya)`. """ # Inherit globally set name self._menu = api.Session["AVALON_LABEL"] + "menu" _register_callbacks() _register_events() _set_project() # Check if maya version is compatible else fix it, Maya2018 only # Should be run regardless of batch mode compat.install() if not IS_HEADLESS: _install_menu() pyblish.register_host("mayabatch") pyblish.register_host("mayapy") pyblish.register_host("maya")
Example #3
Source File: dagmenu.py From mgear_core with MIT License | 6 votes |
def run(*args, **kwargs): # @UnusedVariable """ Menu run execution Args: *args: Variable length argument list. **kwargs: Arbitrary keyword arguments. """ # get check-box state state = args[0] if state: cmds.optionVar(intValue=("mgear_dag_menu_OV", 1)) else: cmds.optionVar(intValue=("mgear_dag_menu_OV", 0)) # runs dag menu right click mgear's override mgear_dagmenu_toggle(state)
Example #4
Source File: interop.py From P4VFX with MIT License | 6 votes |
def initializeMenu(self, entries): try: # gMainWindow = MayaInterop.main_parent_window() gMainWindow = maya.mel.eval('$temp1=$gMainWindow') except RuntimeError as e: print e print 'Are you running in Batch Python?' gMainWindow = None try: print 'Initialising menu...' self.perforceMenu = cmds.menu("PerforceMenu", parent=gMainWindow, tearOff=True, label='Perforce') cmds.setParent(self.perforceMenu, menu=True) except RuntimeError as e: print 'Maya error while trying to create menu:', print e
Example #5
Source File: interop.py From P4VFX with MIT License | 6 votes |
def initializeMenu(self, entries): try: # gMainWindow = MayaInterop.main_parent_window() gMainWindow = maya.mel.eval('$temp1=$gMainWindow') except RuntimeError as e: print e print 'Are you running in Batch Python?' gMainWindow = None try: print 'Initialising menu...' self.perforceMenu = cmds.menu("PerforceMenu", parent=gMainWindow, tearOff=True, label='Perforce') cmds.setParent(self.perforceMenu, menu=True) except RuntimeError as e: print 'Maya error while trying to create menu:', print e
Example #6
Source File: ml_utilities.py From ml_tools with MIT License | 5 votes |
def shelfMenuItem(self, command=None, annotation='', shelfLabel='', shelfIcon='menuIconConstraints', menuLabel='Create Shelf Button'): ''' This creates a menuItem that can be attached to a control to create a shelf menu with the given command ''' pythonCommand = 'import '+self.name+';'+self.name+'.'+command.__name__+'()' mc.menuItem(label=menuLabel, command='import ml_utilities;ml_utilities.createShelfButton(\"'+pythonCommand+'\", \"'+shelfLabel+'\", \"'+self.name+'\", description=\"'+annotation+'\", image=\"'+shelfIcon+'\")', enableCommandRepeat=True, image=shelfIcon)
Example #7
Source File: ml_utilities.py From ml_tools with MIT License | 5 votes |
def createMenu(self, *args): ''' Create the main menu for the UI ''' #generate shelf label by removing ml_ shelfLabel = self.name.replace('ml_','') module = self.module if not module: module = self.name #if icon exists, use that argString = '' if not self.icon: argString = ', label="'+shelfLabel+'"' mc.menu(label='Tools') mc.menuItem(label='Add to shelf', command='import ml_utilities;ml_utilities.createShelfButton("import '+module+';'+module+'.ui()", name="'+self.name+'", description="Open the UI for '+self.name+'."'+argString+')') if not self.icon: mc.menuItem(label='Get Icon', command=(_showHelpCommand(ICON_URL+self.name+'.png'))) mc.menuItem(label='Get More Tools!', command=(_showHelpCommand(WEBSITE_URL+'/tools/'))) mc.setParent( '..', menu=True ) mc.menu(label='Help') mc.menuItem(label='About', command=self.about) mc.menuItem(label='Documentation', command=(_showHelpCommand(TOOL_URL+self.name+'/'))) mc.menuItem(label='Python Command Documentation', command=(_showHelpCommand(TOOL_URL+'#\%5B\%5B'+self.name+'\%20Python\%20Documentation\%5D\%5D'))) mc.menuItem(label='Submit a Bug or Request', command=(_showHelpCommand(WEBSITE_URL+'/about/'))) mc.setParent( '..', menu=True )
Example #8
Source File: ml_utilities.py From ml_tools with MIT License | 5 votes |
def __init__(self, name, title, width=400, height=200, info='', menu=True, module=None): self.name = name self.title = title self.width = width self.height = height self.info = info self.menu = menu self.module = module if not module or module == '__main__': self.module = self.name #look for icon self.icon = getIcon(name)
Example #9
Source File: ml_utilities.py From ml_tools with MIT License | 5 votes |
def dragShiftMiddle(self,*args): '''Placeholder for potential commands. This is meant to be overridden by a child class.''' pass #no drag right, because that is monopolized by the right click menu #no alt drag, because that is used for the camera
Example #10
Source File: ml_toolbox.py From ml_tools with MIT License | 5 votes |
def appendMayaMenu(self, path): ''' Add tools to the maya menus ''' menuLabel = labelFromPath(path) formatLabel = menuLabel.replace(' ','').lower() menuItemArray = mc.menu(self.mainMenus[formatLabel], query=True, itemArray=True) #if this menu hasn't been built yet, run the post menu command to build it #that took a long time to figure out. if not menuItemArray: if self.verbose: print 'pre-building menu: ',menuLabel pmc = mc.menu(self.mainMenus[formatLabel], query=True, postMenuCommand=True) if pmc: mm.eval(pmc) menuItemArray = mc.menu(self.mainMenus[formatLabel], query=True, itemArray=True) #get all the menu items in the menu menuItems = dict() for each in menuItemArray: eachLabel = mc.menuItem(each, query=True, label=True) menuItems[eachLabel] = each subItems = [posixpath.join(path,x) for x in os.listdir(path) if (x.endswith('.py') or x.endswith('.mel')) and x != '__init__.py'] if subItems: for path in subItems: tool = Tool(path) self.classifyTool(tool) if not tool.errors: tool.createMenuItem(parent=self.mainMenus[formatLabel], labelPrefix=MENU_ITEM_PREFIX+' ', italicized=True)
Example #11
Source File: menu.py From cmt with MIT License | 5 votes |
def about(): """Displays the CMT About dialog.""" name = "cmt_about" if cmds.window(name, exists=True): cmds.deleteUI(name, window=True) if cmds.windowPref(name, exists=True): cmds.windowPref(name, remove=True) window = cmds.window( name, title="About CMT", widthHeight=(600, 500), sizeable=False ) form = cmds.formLayout(nd=100) text = cmds.scrollField(editable=False, wordWrap=True, text=cmt.__doc__.strip()) button = cmds.button( label="Documentation", command="import cmt.menu; cmt.menu.documentation()" ) margin = 8 cmds.formLayout( form, e=True, attachForm=( (text, "top", margin), (text, "right", margin), (text, "left", margin), (text, "bottom", 40), (button, "right", margin), (button, "left", margin), (button, "bottom", margin), ), attachControl=((button, "top", 2, text)), ) cmds.showWindow(window)
Example #12
Source File: interop.py From P4VFX with MIT License | 5 votes |
def addMenuCommand(self, label, icon, command): try: cmds.menuItem( label=label, image=icon, command=command ) except RuntimeError as e: print 'Maya error while trying to change menu parent:', print e
Example #13
Source File: interop.py From P4VFX with MIT License | 5 votes |
def addMenuSubmenu(self, label, icon, entries): try: cmds.menuItem(subMenu=True, tearOff=False, label=label, image=icon) except RuntimeError as e: print 'Maya error while trying to create submenu:', print e self.fillMenu(entries) try: cmds.setParent('..', menu=True ) except RuntimeError as e: print 'Maya error while trying to change menu parent:', print e
Example #14
Source File: interop.py From P4VFX with MIT License | 5 votes |
def addMenuCommand(self, label, icon, command): try: cmds.menuItem( label=label, image=icon, command=command ) except RuntimeError as e: print 'Maya error while trying to change menu parent:', print e
Example #15
Source File: interop.py From P4VFX with MIT License | 5 votes |
def addMenuSubmenu(self, label, icon, entries): try: cmds.menuItem(subMenu=True, tearOff=False, label=label, image=icon) except RuntimeError as e: print 'Maya error while trying to create submenu:', print e self.fillMenu(entries) try: cmds.setParent('..', menu=True ) except RuntimeError as e: print 'Maya error while trying to change menu parent:', print e
Example #16
Source File: interop.py From P4VFX with MIT License | 5 votes |
def addMenuLabel(self, label): try: cmds.menuItem(label=label, en=False) except RuntimeError as e: print 'Maya error while trying to add menu entry:', print e
Example #17
Source File: mlSSDS.py From ssds with MIT License | 5 votes |
def deleteUI(): try: cmds.deleteUI('SSDS', menuItem = True) except: pass try: itemArray = cmds.menu('MukaiLab', query = True, itemArray = True) if itemArray == None: cmds.deleteUI('MukaiLab') except: pass
Example #18
Source File: mlSSDS.py From ssds with MIT License | 5 votes |
def createUI(): cmds.setParent('MayaWindow') try: cmds.menu('MukaiLab', query = True, label = True) except: cmds.menu('MukaiLab', label = 'MukaiLab') cmds.setParent('MukaiLab', menu = True) cmds.menuItem('SSDS', label = 'SSDS', command = showBuildWindow)
Example #19
Source File: pyMyPlugin.py From MayaDev with MIT License | 5 votes |
def uninitializePlugin(mobject): """Uninitialize the plug-in and delete menu""" plugin = om.MFnPlugin(mobject) try: plugin.deregisterCommand(kPluginCmdName) removeMenu(menuName=kPluginCmdName) # removeShelf(shelfName=kPluginCmdName) except: sys.stderr.write('Failed to unregister command: %s\n' % kPluginCmdName) raise
Example #20
Source File: pyMyPlugin.py From MayaDev with MIT License | 5 votes |
def initializePlugin(mobject): """Initialize the plug-in and add menu""" errMsg = u'Failed to register command: %s\n' % kPluginCmdName plugin = om.MFnPlugin(mobject, kPluginVendor, kPluginVersion) try: plugin.registerCommand(kPluginCmdName, MyDemo.creator) makeMenu(menuName=kPluginCmdName) # makeShelf(shelfName=kPluginCmdName) except: sys.stderr.write(errMsg) raise # Uninitialize # ----------------------------------------------------------------------
Example #21
Source File: pyMyPlugin.py From MayaDev with MIT License | 5 votes |
def makeMenu(menuName=kPluginCmdName): """make menu when plugin load""" removeMenu(menuName) topMenu = cmds.menu(menuName, label=menuName, parent=u'MayaWindow', tearOff=True) cmds.menuItem(label=kPluginCmdName, parent=topMenu, command=kPluginCmdName, sourceType='mel') # Plugin class # ----------------------------------------------------------------------
Example #22
Source File: pyMyPlugin.py From MayaDev with MIT License | 5 votes |
def removeMenu(menuName=kPluginCmdName): """remove menu when plugin unload""" if cmds.menu(menuName, q=True, exists=True): cmds.deleteUI(menuName, menu=True)
Example #23
Source File: dagmenu.py From mgear_core with MIT License | 5 votes |
def mgear_dagmenu_callback(*args, **kwargs): # @UnusedVariable """ Triggers dag menu display If selection is ends with **_ctl** then display mGear's contextual menu. Else display Maya's standard right click dag menu Args: *args: Parent Menu path name / Variable length argument list. **kwargs: Arbitrary keyword arguments. Returns: str: Menu object name/path that is passed to the function """ # cast args into more descend variable name parent_menu = args[0] # if second argument if not a bool then means that we are running # the override if type(args[1]) != bool: sel = cmds.ls(selection=True, long=True, exactType="transform") if sel and cmds.objExists("{}.isCtl".format(sel[0])): # cleans menu _parent_menu = parent_menu.replace('"', '') cmds.menu(_parent_menu, edit=True, deleteAllItems=True) # fills menu mgear_dagmenu_fill(_parent_menu, sel[0]) else: mel.eval("buildObjectMenuItemsNow " + parent_menu) # always return parent menu path return parent_menu
Example #24
Source File: dagmenu.py From mgear_core with MIT License | 5 votes |
def install(): """ Installs dag menu option """ # get state state = get_option_var_state() cmds.setParent(mgear.menu_id, menu=True) cmds.menuItem("mgear_dagmenu_menuitem", label="mGear Viewport Menu ", command=run, checkBox=state) cmds.menuItem(divider=True) run(state)
Example #25
Source File: dagmenu.py From mgear_core with MIT License | 5 votes |
def get_option_var_state(): """ Gets dag menu option variable Maya's optionVar command installs a variable that is kept on Maya's settings so that you can use it on future sessions. Maya's optionVar are a quick and simple way to store a custom variable on Maya's settings but beware that they are kept even after mGear's uninstall so you will need to run the following commands. Returns: bool: Whether or not mGear's dag menu override is used Example: The following removes mgears dag menu optionVar .. code-block:: python from maya import cmds if not cmds.optionVar(exists="mgear_dag_menu_OV"): cmds.optionVar(remove="mgear_dag_menu_OV") """ # if there is no optionVar the create one that will live during maya # current and following sessions if not cmds.optionVar(exists="mgear_dag_menu_OV"): cmds.optionVar(intValue=("mgear_dag_menu_OV", 0)) return cmds.optionVar(query="mgear_dag_menu_OV")
Example #26
Source File: dpAutoRig.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def changeOptionDegree(self, degreeOption, *args): """ Set optionVar to choosen menu item. """ cmds.optionVar(stringValue=('dpAutoRigLastDegreeOption', degreeOption)) self.degreeOption = int(degreeOption[0])
Example #27
Source File: pipeline.py From core with MIT License | 5 votes |
def _update_menu_task_label(): """Update the task label in Avalon menu to current session""" if IS_HEADLESS: return object_name = "{}|currentContext".format(self._menu) if not cmds.menuItem(object_name, query=True, exists=True): logger.warning("Can't find menuItem: {}".format(object_name)) return label = "{}, {}".format(api.Session["AVALON_ASSET"], api.Session["AVALON_TASK"]) cmds.menuItem(object_name, edit=True, label=label)
Example #28
Source File: pipeline.py From core with MIT License | 5 votes |
def _uninstall_menu(): # In Maya 2020+ don't use the QApplication.instance() # during startup (userSetup.py) as it will return a # QtCore.QCoreApplication instance which does not have # the allWidgets method. As such, we call the staticmethod. all_widgets = QtWidgets.QApplication.allWidgets() widgets = dict((w.objectName(), w) for w in all_widgets) menu = widgets.get(self._menu) if menu: menu.deleteLater() del(menu)
Example #29
Source File: dagmenu.py From mgear_core with MIT License | 4 votes |
def mgear_dagmenu_toggle(state): """Set on or off the mgear dag menu override This function is responsible for turning ON or OFF mgear's right click menu override. When turned on this will interact with dag nodes that have **_ctl** at the end of their name. Args: state (bool): Whether or not to override Maya's dag menu with mGear's dag menu """ # First loop on Maya menus as Maya's dag menu is a menu for maya_menu in cmds.lsUI(menus=True): # We now get the menu's post command which is a command used for # dag menu menu_cmd = cmds.menu(maya_menu, query=True, postMenuCommand=True) or [] # If state is set top True then override Maya's dag menu if state and type(menu_cmd) == unicode: if "buildObjectMenuItemsNow" in menu_cmd: # Maya's dag menu post command has the parent menu in it parent_menu = menu_cmd.split(" ")[-1] # Override dag menu with custom command call cmds.menu(maya_menu, edit=True, postMenuCommand=partial( mgear_dagmenu_callback, parent_menu)) # If state is set to False then put back Maya's dag menu # This is tricky because Maya's default menu command is a MEL call # The override part uses a python function partial call and because of # this we need to do some small hack on mGear_dag_menu_callback to give # back the default state of Maya's dag menu elif not state and type(menu_cmd) == partial: # we now check if the command override is one from us # here because we override original function we need # to get the function name by using partial.func if "mgear_dagmenu_callback" in menu_cmd.func.__name__: # we call the mGear_dag_menu_callback with the future state # this will return the original menu parent so that we # can put Maya's original dag menu command in mel parent_menu = menu_cmd(state) # we set the old mel command # don't edit any space or syntax here as this is what Maya # expects mel.eval('menu -edit -postMenuCommand ' '"buildObjectMenuItemsNow ' + parent_menu.replace('"', '') + '"' + maya_menu)
Example #30
Source File: ml_toolbox.py From ml_tools with MIT License | 4 votes |
def createMainMenus(self): #mayas main window menu: gMainWindow = mm.eval('$temp=$gMainWindow') #get all the menus that are children of the main menu mainWindowMenus = mc.window(gMainWindow, query=True, menuArray=True) #get the label for each of the menus #this will be matched against tool directories self.mainMenus = dict() for name in mainWindowMenus: label = mc.menu(name, query=True, label=True) #we need to make the label all lower case and no spaces, so we can match properly. formatLabel = label.replace(' ','').lower() self.mainMenus[formatLabel] = name mayaMenuDirectories = list() customMenuDirectories = list() for folder in os.listdir(self.menusPath): if folder.startswith('.'): continue toolDirectory = posixpath.join(self.menusPath,folder) #only directories for this first level if not os.path.isdir(toolDirectory): if not folder.startswith('__init__') and self.verbose: print 'Root level file being ignored, move this to a sub-directory: ',toolDirectory continue menuLabel = labelFromPath(toolDirectory) formatLabel = menuLabel.replace(' ','').lower() if formatLabel in self.mainMenus and not self.mainMenus[formatLabel].startswith(MAIN_MENU_NAME_PREFIX): #maya menus mayaMenuDirectories.append(toolDirectory) else: #custom menu customMenuDirectories.append(toolDirectory) if mayaMenuDirectories: for d in mayaMenuDirectories: self.appendMayaMenu(d) if customMenuDirectories: for d in customMenuDirectories: self.createCustomMenu(d, parent=gMainWindow, mainMenu=True) self.setHotkeys()