Python maya.cmds.menuItem() Examples
The following are 30
code examples of maya.cmds.menuItem().
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_arcTracer.py From ml_tools with MIT License | 6 votes |
def markingMenu(): ''' Example of how a marking menu could be set up. ''' menuKwargs = {'enable':True, 'subMenu':False, 'enableCommandRepeat':True, 'optionBox':False, 'boldFont':True} mc.menuItem(radialPosition='N', label='Trace Camera', command=traceCamera, **menuKwargs) mc.menuItem(radialPosition='E', label='Trace World', command=traceWorld, **menuKwargs) mc.menuItem(radialPosition='W', label='Re-Trace', command=retraceArc, **menuKwargs) mc.menuItem(radialPosition='S', label='Clear', command=clearArcs, **menuKwargs) mc.menuItem(label='Arc Tracer UI', command=ui, **menuKwargs)
Example #2
Source File: ml_puppet.py From ml_tools with MIT License | 6 votes |
def attributeMenuItem(node, attr): plug = node+'.'+attr niceName = mc.attributeName(plug, nice=True) #get attribute type attrType = mc.getAttr(plug, type=True) if attrType == 'enum': listEnum = mc.attributeQuery(attr, node=node, listEnum=True)[0] if not ':' in listEnum: return listEnum = listEnum.split(':') mc.menuItem(label=niceName, subMenu=True) for value, label in enumerate(listEnum): mc.menuItem(label=label, command=partial(mc.setAttr, plug, value)) mc.setParent('..', menu=True) elif attrType == 'bool': value = mc.getAttr(plug) label = 'Toggle '+ niceName mc.menuItem(label=label, command=partial(mc.setAttr, plug, not value))
Example #3
Source File: dagmenu.py From mgear_core with MIT License | 6 votes |
def __mirror_flip_pose_callback(*args): """Wrapper function to call mGears mirroPose function Args: list: callback from menuItem """ # cast controls into pymel object nodes controls = [pm.PyNode(x) for x in args[0]] # triggers mirror # we handle the mirror/flip each control individually even if the function # accepts several controls. Flipping on proxy attributes like blend # attributes cause an issue to rather than trying the complete list we do # one control to avoid the mirror to stop for ctl in controls: mirrorPose(flip=args[1], nodes=[ctl])
Example #4
Source File: dagmenu.py From mgear_core with MIT License | 6 votes |
def __reset_attributes_callback(*args): """ Wrapper function to call mGears resetTransform function Args: list: callback from menuItem """ attribute = args[1] for node in args[0]: control = pm.PyNode(node) if attribute == "translate": resetTransform(control, t=True, r=False, s=False) if attribute == "rotate": resetTransform(control, t=False, r=True, s=False) if attribute == "scale": resetTransform(control, t=False, r=False, s=True)
Example #5
Source File: ml_graphEditorMask.py From ml_tools with MIT License | 6 votes |
def markingMenu(): ''' Example of how a marking menu could be set up. ''' menuKwargs = {'enable':True, 'subMenu':False, 'enableCommandRepeat':True, 'optionBox':False, 'boldFont':True} mc.menuItem(radialPosition='NW', label='Trans', command=translate, **menuKwargs) mc.menuItem(radialPosition='N', label='Rot', command=rotate, **menuKwargs) mc.menuItem(radialPosition='NE', label='Scale', command=scale, **menuKwargs) mc.menuItem(radialPosition='SW', label='X', command=x, **menuKwargs) mc.menuItem(radialPosition='S', label='Y', command=y, **menuKwargs) mc.menuItem(radialPosition='SE', label='Z', command=z, **menuKwargs) mc.menuItem(radialPosition='W', label='ChanBox', command=channelBox, **menuKwargs) mc.menuItem(radialPosition='E', label='Sel', command=selected, **menuKwargs) mc.menuItem(label='All', command=showAll, **menuKwargs)
Example #6
Source File: optionbox.py From cmt with MIT License | 6 votes |
def __init__(self, title, help_url=None): layout = mel.eval("getOptionBox") cmds.setParent(layout) mel.eval('setOptionBoxTitle("{}");'.format(title)) self.create_ui() apply_close_button = mel.eval("getOptionBoxApplyAndCloseBtn;") cmds.button(apply_close_button, e=True, command=self._apply_and_close) apply_button = mel.eval("getOptionBoxApplyBtn;") cmds.button(apply_button, e=True, command=self._on_apply) close_button = mel.eval("getOptionBoxCloseBtn;") cmds.button(close_button, e=True, command=self._close) if help_url: help_item = mel.eval("getOptionBoxHelpItem;") cmds.menuItem( help_item, e=True, label="Help on {}".format(title), command='import webbrowser; webbrowser.open("{}")'.format(help_url), )
Example #7
Source File: commands.py From maya-command-search with GNU General Public License v3.0 | 5 votes |
def getItem(item, name, parents): """ Get data from item and store it into COMMANDS variable. :param QWidgetAction item: :param str name: :param list parents: List f all parents, used for hierarchy """ # get name text = item.text().encode("utf-8") if not name or item.isSeparator() or item.menu(): return # add last parent parents.append(text) # get icon icon = cmds.menuItem(utils.qtToMaya(item), query=True, image=True) # store commands COMMANDS[name] = dict( ) COMMANDS[name]["name"] = text COMMANDS[name]["pin"] = False COMMANDS[name]["cmd"] = item COMMANDS[name]["icon"] = utils.QIcon( ":/{0}".format(icon)) COMMANDS[name]["group"] = parents[0] COMMANDS[name]["search"] = "".join([p.lower() for p in parents]) COMMANDS[name]["hierarchy"] = " > ".join(parents)
Example #8
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 #9
Source File: interop.py From P4VFX with MIT License | 5 votes |
def addMenuDivider(self, label): try: cmds.menuItem(divider=True, label=label) except RuntimeError as e: print 'Maya error while trying to create divider:', print e
Example #10
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 #11
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 #12
Source File: lib.py From pyblish-maya with GNU Lesser General Public License v3.0 | 5 votes |
def remove_from_filemenu(): for item in ("pyblishOpeningDivider", "pyblishScene", "pyblishCloseDivider"): if cmds.menuItem(item, exists=True): cmds.deleteUI(item, menuItem=True)
Example #13
Source File: lib.py From pyblish-maya with GNU Lesser General Public License v3.0 | 5 votes |
def _add_to_filemenu(): """Helper function for the above :func:add_to_filemenu() This function is serialised into a string and passed on to evalDeferred above. """ import os import pyblish from maya import cmds # This must be duplicated here, due to this function # not being available through the above `evalDeferred` for item in ("pyblishOpeningDivider", "pyblishScene", "pyblishCloseDivider"): if cmds.menuItem(item, exists=True): cmds.deleteUI(item, menuItem=True) icon = os.path.dirname(pyblish.__file__) icon = os.path.join(icon, "icons", "logo-32x32.svg") cmds.menuItem("pyblishOpeningDivider", divider=True, insertAfter="saveAsOptions", parent="mainFileMenu") cmds.menuItem("pyblishScene", insertAfter="pyblishOpeningDivider", label="Publish", parent="mainFileMenu", image=icon, command="import pyblish_maya;pyblish_maya.show()") cmds.menuItem("pyblishCloseDivider", insertAfter="pyblishScene", parent="mainFileMenu", divider=True)
Example #14
Source File: optionbox.py From cmt with MIT License | 5 votes |
def show(self): mel.eval("showOptionBox") # In getOptionBox.mel showOptionBox, it sets the Reset and Save menu item # commands in MEL so they expect MEL code. We want Python so override the # commands after showing the option box in order to use Python reset_item = mel.eval("$tmp = $gOptionBoxEditMenuResetItem") cmds.menuItem(reset_item, e=True, command=self._on_reset) save_item = mel.eval("$tmp = $gOptionBoxEditMenuSaveItem") cmds.menuItem(save_item, e=True, command=self._on_save)
Example #15
Source File: ml_copyAnim.py From ml_tools with MIT License | 5 votes |
def markingMenu(): ''' Example of how a marking menu could be set up. ''' menuKwargs = {'enable':True, 'subMenu':False, 'enableCommandRepeat':True, 'optionBox':False, 'boldFont':True} mc.menuItem(radialPosition='E', label='Copy Hierarchy', command=copyHierarchy, **menuKwargs) mc.menuItem(radialPosition='W', label='Copy Single', command=copySingle, **menuKwargs) mc.menuItem(label='Copy Anim UI', command=ui, **menuKwargs)
Example #16
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 #17
Source File: ml_controlLibrary.py From ml_tools with MIT License | 5 votes |
def refreshShelfLayout(self, *args): '''Delete and the shelf buttons and remake them ''' shelfButtons = mc.shelfLayout(self.shelfLayout, query=True, childArray=True) if shelfButtons: for child in shelfButtons: mc.deleteUI(child) mc.setParent(self.shelfLayout) for each in os.listdir(REPOSITORY_PATH): if each.endswith('.ctrl'): name = os.path.splitext(each)[0] icon = None imageFile = os.path.join(REPOSITORY_PATH,name+'.png') if os.path.isfile(imageFile): icon = imageFile filename = os.path.join(REPOSITORY_PATH,each) button = mc.shelfButton(command=partial(importControl, name), image=icon, width=70, height=70, imageOverlayLabel=name.replace('_',' ').replace(' ',' '), annotation=name) menus = mc.shelfButton(button, query=True, popupMenuArray=True) if menus: for menu in menus: mc.deleteUI(menu) #mc.popupMenu() #mc.menuItem('delete', command=partial(self.deleteShelfButton, name))
Example #18
Source File: ml_utilities.py From ml_tools with MIT License | 5 votes |
def buildWindow(self): ''' Initialize the UI ''' if mc.window(self.name, exists=True): mc.deleteUI(self.name) mc.window(self.name, title='ml :: '+self.title, iconName=self.title, width=self.width, height=self.height, menuBar=self.menu) if self.menu: self.createMenu() self.form = mc.formLayout() self.column = mc.columnLayout(adj=True) mc.rowLayout( numberOfColumns=2, columnWidth2=(34, self.width-34), adjustableColumn=2, columnAlign2=('right','left'), columnAttach=[(1, 'both', 0), (2, 'both', 8)] ) #if we can find an icon, use that, otherwise do the text version if self.icon: mc.iconTextStaticLabel(style='iconOnly', image1=self.icon) else: mc.text(label=' _ _ |\n| | | |') if not self.menu: mc.popupMenu(button=1) mc.menuItem(label='Help', command=(_showHelpCommand(TOOL_URL+self.name+'/'))) mc.text(label=self.info) mc.setParent('..') mc.separator(height=8, style='single', horizontal=True)
Example #19
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 #20
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 #21
Source File: ml_utilities.py From ml_tools with MIT License | 5 votes |
def hotkeyMenuItem(self, command=None, annotation='', menuLabel='Create Hotkey'): ''' This creates a menuItem that can be attached to a control to create a hotkey with the given command ''' melCommand = 'import '+self.name+';'+self.name+'.'+command.__name__+'()' mc.menuItem(label=menuLabel, command='import ml_utilities;ml_utilities.createHotkey(\"'+melCommand+'\", \"'+self.name+'\", description=\"'+annotation+'\")', enableCommandRepeat=True, image='commandButton')
Example #22
Source File: startup.py From SIWeightEditor with MIT License | 5 votes |
def menu_setup(): #Maya_Windowが見つからない場合はスタートしない if not qt.get_maya_window(): return cmd = ''' buildViewMenu MayaWindow|mainWindowMenu; setParent -menu "MayaWindow|mainWindowMenu"; ''' mel.eval(cmd) cmds.menuItem(divider=True) cmds.menuItem( 'siweighteditor_folder', label='SiWeightEditor', subMenu=True, tearOff=True ) cmds.menuItem( 'siweighteditor_open', label=jpn('SiWeightEditor'), annotation="open SiWeightEditor", parent='siweighteditor_folder', echoCommand=True, command=dedent( ''' import siweighteditor.siweighteditor siweighteditor.siweighteditor.Option() ''') )
Example #23
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 #24
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 #25
Source File: dpAutoRig.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def getCurrentMenuValue(self, itemList, *args): for item in itemList: if cmds.menuItem( item+"_MI", query=True, radioButton=True ): return item
Example #26
Source File: dpSpine.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def reCreateEditSelectedModuleLayout(self, bSelect=False, *args): Layout.LayoutClass.reCreateEditSelectedModuleLayout(self, bSelect) # style layout: self.styleLayout = cmds.rowLayout(numberOfColumns=4, columnWidth4=(100, 50, 50, 70), columnAlign=[(1, 'right'), (2, 'left'), (3, 'right')], adjustableColumn=4, columnAttach=[(1, 'both', 2), (2, 'left', 2), (3, 'left', 2), (3, 'both', 10)], parent="selectedColumn") cmds.text(label=self.langDic[self.langName]['m041_style'], visible=True, parent=self.styleLayout) self.styleMenu = cmds.optionMenu("styleMenu", label='', changeCommand=self.changeStyle, parent=self.styleLayout) styleMenuItemList = [self.langDic[self.langName]['m042_default'], self.langDic[self.langName]['m026_biped']] for item in styleMenuItemList: cmds.menuItem(label=item, parent=self.styleMenu) # read from guide attribute the current value to style: currentStyle = cmds.getAttr(self.moduleGrp+".style") cmds.optionMenu(self.styleMenu, edit=True, select=int(currentStyle+1))
Example #27
Source File: dagmenu.py From mgear_core with MIT License | 5 votes |
def __change_rotate_order_callback(*args): """Wrapper function to call mGears change rotate order function Args: list: callback from menuItem """ # triggers rotate order change change_rotate_order(args[0], args[1])
Example #28
Source File: dagmenu.py From mgear_core with MIT License | 5 votes |
def __keyframe_nodes_callback(*args): """Wrapper function to call Maya's setKeyframe command on given controls Args: list: callback from menuItem """ cmds.setKeyframe(args[0])
Example #29
Source File: dagmenu.py From mgear_core with MIT License | 5 votes |
def __select_nodes_callback(*args): """ Wrapper function to call Maya select command Args: list: callback from menuItem """ cmds.select(args[0], add=True)
Example #30
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)