MGPickerMenuItem
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:
# The 1st menu item in right click menu for "commandButton1"
"commandButton1.rightmenu[0] "
# The 4th subMenu item in 2nd menuitem in left click menu for "selectButton1"
"selectButton1.leftmenu[1][3]"
For now in picker & in API, only one level of sub menu supported.
Go to: [MEL Examples] [Python Examples]
Synopsis
MGPickerMenuItem( addSubMenuItem=(string, string, string, string, string), command=string, commandType=string, divider=boolean, deleteAllSubItems=boolean, dividerLabel=string, exist=boolean, image=string, queryFullImagePath=boolean, 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 |
|---|
-addSubMenuItem(-asi) string string string string string
|
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”).
|
-command(-c) string
|
The command of menu item. |
-commandType(-ct) string
|
The command type of menu item: “mel” or “python”. |
-divider(-d) boolean
|
The menu item is a separator or not. |
-deleteAllSubItems(-dai)
|
Delete all sub menu items of current menu item. |
-dividerLabel(-dl) string
|
The divider label of current menu item. Only shown when menu item is a separator (dividier=True). |
-exist(-ex)
|
This is a query only flag that can be used to query for the existence of a specific picker menu item. |
-image(-i) string
|
The icon path for the menu item. |
-queryFullImagePath(-ifp)
|
Whether to query the absolute full path when querying image paths. Used with other flags. |
-insertSubMenuItem(-isi) int string string string string string
|
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”).
|
-label(-l) string
|
The label string of the menu item. |
-longDivider(-ld) boolean
|
Whether or not it should be a long divider if the menu item is a separator (dividier=True). |
-numberOfSubItems(-nsi)
|
The number of sub menu items. |
-parent(-p) string
|
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
|
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)
|
Return list of sub menu item id string array. |
-subMenu(-sm) boolean
|
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
|
This is a query only flag, for retrieving the sub menu item id string at specific index. |
-view(-v) string
|
Specify which picker view we wanna create / edit / query the picker menu item. |
Flag can appear in Create mode
Flag can appear in Edit mode
Flag can appear in Query mode
Flag can be used more than once.
MEL examples
// You must make sure the picker item: commandButton1 is already in scene.
// To form a picker menu id, use pickerItemId.leftmenu / pickerItemId.rightmenu
string $cmdButton = "commandButton1";
//This just retrieves the id "commandButton1.rightmenu" instead of creating it.
string $rightMenu = `MGPickerMenu -p $cmdButton -m "rightmenu"`;
// 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
from mgpicker import mgp
# You must make sure the picker item: commandButton1 is already in scene.
# To form a picker menu id, use pickerItemId.leftmenu / pickerItemId.rightmenu
cmdButton = "commandButton1"
# This just retrieves the id "commandButton1.rightmenu" instead of creating it.
rightMenu = mgp.MGPickerMenu(p=cmdButton, mode="rightmenu")
# We get a menu item id via -addMenuItem or -insertMenuItem flag of MGPickerMenu command:
menuItem0 = mgp.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 = mgp.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:
mgp.MGPickerMenuItem(menuItem0, e=True, subMenu=True)
# Like we did above, add submenu items:
subMenuItem1 = mgp.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 = mgp.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!'",
)