Home  Previous Next

command (MEL/Python)

MGPickerMenuItem

Go to: MEL synopsis. Python synopsis. Return value. Flags. MEL examples. Python examples.

MEL Synopsis

MGPickerMenuItemItem [-addSubMenuItem] [-command] [-commandType] [-divider] [-dividerLabel] [-exist] [-image] [-insertSubMenuItem] [-label] [-longDivider] [-numberOfSubItems] [-parent] [-radialPosition] [-subItemArray] [-subMenu] [-subMenuItem] [-view] menuItemIDString

Python Synopsis

MGPickerMenuItem (menuItemIDString, [addSubMenuItem=(string, string, string, string, string)], [command=boolean], [commandType=string], [divider=boolean], [dividerLabel=string], [exist=boolean], [image=string], [insertSubMenuItem=(int, string, string, string, string, string)], [label=string], [longDivider=boolean], [numberOfSubItems=boolean],[parent=string],[radialPosition=string], [subItemArray=boolean], [subMenu=boolean], [subMenuItem=int], [view=string])

MGPickerMenuItem is NOT undoable, queryable, and editable.

This command create / queries / edits picker menu.

You always need to specify the picker menu id string to query / edit it.

In create mode, it will add a picker menu item for the parent menu / menuitem specified by -parent flag.

A picker menu item id string is something like:

 commandButton1.rightmenu[0]                //The first menu item in right click menu for the picker item of id "commandButton1"

 selectButton1.leftmenu[1][3]                //The 4th sub menu item in second menuitem in left click menu for the picker item of id "selectButton1"

 

For now in picker & in API, only one level of sub menu supported.

Return value

Usually it returns the menu item id string or the sub-menu item id string if it is for adding / inserting sub menu item.

Flags

addSubMenuItem, command, commandType, divider, dividerLabel, exist, image, insertSubMenuItem, label, longDivider, numberOfSubItems, parent, radialPosition, subItemArray, subMenu, subMenuItem, view,

 

Long name (short name)

Argument types

Properties

-addSubMenuItem(-asi)

string string string script string

createedit


Add a sub menu item to current menu item. If current menu item is already a sub menu item, it will do nothing and return empty id string, since MGPicker only support one level of sub-menu.

Specify label, icon path, command type ("mel" or "python"), command and the radial position for marking menu position ("N", "NW", "W", "SW", "S", "SE", "E" or "NE").

* Keep in mind that, if this flag is used in create mode, it will still return the added sub-menu item id instead of current menu item id.

* Also if current menu item is already a sub menu item, this flag won't work and just return empty id.

-command(-c)

string

createqueryedit


The command of menu item.

-commandType(-ct)

string

createqueryedit


The command type of menu item: "mel" or  "python".

-divider(-d)

boolean

createqueryedit


The menu item is a separator or not.

-deleteAllSubItems(-dai)

 

createedit


Delete all sub menu items of current menu item.

-dividerLabel(-dl)

boolean

createqueryedit


The divider label of current menu item. Only shown when menu item is a separator (dividier=True).

-exist(-ex)


query


This is a query only flag that can be used to query for the existence of a specific picker menu item.

-image(-i)

string

createqueryedit


The icon path for the menu item.

-insertSubMenuItem(-isi)

int string string string script string

createedit


Insert a sub-menu item to current picker menu item at certain index. Specify index small than 0 will just prepend sub-menu item at first index, index larger than last item index will just append sub-menu item.

Specify index, label, icon path, command type ("mel" or "python"), command and the radial position for marking menu position ("N", "NW", "W", "SW", "S", "SE", "E" or "NE").

* Keep in mind that, if this flag is used in create mode, it will still return the inserted sub-menu item id instead of current menu item id.

-label(-l)

string

createqueryedit


The label string of the menu item.

-longDivider(-ld)

boolean

createqueryedit


Whether or not it should be a long divider if the menu item is a separator (dividier=True).

-numberOfSubItems(-nsi)

 

query


The number of sub menu items.

-parent(-p)

string

createquery


In query mode, it returns the picker menu / menu item id this menu item belong to. In create mode, this is a must have flag, to specify for which menu / menu item we wanna add a menu item.

-radialPosition(-rp)

string

createqueryedit


The radial position for the menu item: "N", "NW", "W", "SW", "S", "SE", "E" or "NE". You still need to turn on the markingMenu flag for the menu to make it take effect.

-subItemArray(-sia)

 

query


Return list of sub menu item id string array.

-subMenu(-sm)

boolean

createqueryedit


Decide current menu item should be a sub menu that can contain sub-menu items. If current menu item is already a sub-menu item, this flag takes no effect.

-subMenuItem(-smi)

int

query


This is a query only flag, for retrieving the sub menu item id string at specific index.

-view(-v)

string

createqueryedit


Specify which picker view we wanna create / edit / query the picker menu item.














create Flag can appear in Create mode of command

edit Flag can appear in Edit mode of command

query Flag can appear in Query mode of command

multiuse Flag can be used more than once in a command.

MEL examples

// You must make sure the picker item: commandButton1 is already in scene in order to test these codes.
// To form a picker menu id, use pickerItemId.leftmenu / pickerItemId.rightmenu
string $cmdButton = "commandButton1";
string $rightMenu = `MGPickerMenu -p $cmdButton -m "rightmenu"`;        //This just retrieves the id "commandButton1.rightmenu" instead of creating it.
 
// We get a menu item id via -addMenuItem or -insertMenuItem flag of MGPickerMenu command:
string $menuItem0 = `MGPickerMenu -e -addMenuItem "First Menu Item" "/path/to/icon0.png" "mel" "print \"It works!\"" "N" $rightMenu`;
 
// We can add a menu item using MGPickerMenuItem command:
string $menuItem1 = `MGPickerMenuItem -parent $rightMenu 
                                           -label "Second Menu Item" 
                                           -image "/path/to/icon1.png" 
                                           -commandType "mel" 
                                           -command "print \"The MGPickerMenuItem in create mode works !\"" 
                                           -radialPosition "N"`;

// We can also make a menu item a sub menu:
MGPickerMenuItem -e -subMenu 1 $menuItem0;
 
// Like we did above, add submenu items:
string $subMenuItem1 = `MGPickerMenuItem -e -addSubMenuItem "First SubMenu Item" "/path/to/icon.png" "python" "print 'Sub menu item works!'" "" $menuItem0`;
 
// We can also add a sub-menu item using MGPickerMenuItem command:
string $subMenuItem2 = `MGPickerMenuItem -parent $menuItem0 
                                           -label "Second SubMenu Item" 
                                           -image "/path/to/icon.png" 
                                           -commandType "python" 
                                           -command "print 'The MGPickerMenuItem in create mode also works for submenu item!'"`;
 

Python examples

import maya.cmds as cmd

# You must make sure the picker item: commandButton1 is already in scene in order to test these codes.
# To form a picker menu id, use pickerItemId.leftmenu / pickerItemId.rightmenu
cmdButton = 'commandButton1'
rightMenu = cmds.MGPickerMenu(p=cmdButton, mode='rightmenu') # This just retrieves the id "commandButton1.rightmenu" instead of creating it.
 
#  We get a menu item id via -addMenuItem or -insertMenuItem flag of MGPickerMenu command:
menuItem0 = cmds.MGPickerMenu(rightMenu, e=True, addMenuItem=('First Menu Item', '/path/to/icon0.png', 'mel', 'print "It works!"', 'N'))
# We can add a menu item using MGPickerMenuItem command:
menuItem1 = cmds.MGPickerMenuItem(parent=rightMenu, 
                                  label='Second Menu Item',  
                                  image='/path/to/icon1.png', 
                                  commandType='mel',  
                                  command='print "The MGPickerMenuItem in create mode works !"')

# We can also make a menu item a sub menu:
cmds.MGPickerMenuItem(menuItem0, e=True, subMenu=True)
 
# Like we did above, add submenu items:
subMenuItem1 = cmds.MGPickerMenuItem(menuItem0, e=True, addSubMenuItem=('First SubMenu Item', '/path/to/icon0.png', 'mel', 'print "Sub menu works!"', ''))
 
# We can also add a sub-menu item using MGPickerMenuItem command:
subMenuItem2 = cmds.MGPickerMenuItem(parent=menuItem0, 
                                     label='Second SubMenu Item', 
                                     image='/path/to/icon.png', 
                                     commandType='python', 
                                     command="print 'The MGPickerMenuItem in create mode also works for submenu item!'")

Home Previous Next