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]

MGPickerMenuItem

-addSubMenuItem(-asi)string string string string stringC E

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)stringC Q E

The command of menu item.

-commandType(-ct)stringC Q E

The command type of menu item: “mel” or “python”.

-divider(-d)booleanC Q E

The menu item is a separator or not.

-deleteAllSubItems(-dai)C Q E

Delete all sub menu items of current menu item.

-dividerLabel(-dl)stringC Q E

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

-exist(-ex)Q

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

-image(-i)stringC Q E

The icon path for the menu item.

-queryFullImagePath(-ifp)Q

Whether to query the absolute full path when querying image paths. Used with other flags.

-insertSubMenuItem(-isi)int string string string string stringC Q E

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)stringC Q E

The label string of the menu item.

-longDivider(-ld)booleanC Q E

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

-numberOfSubItems(-nsi)Q

The number of sub menu items.

-parent(-p)stringC Q

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)stringC Q E

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)Q

Return list of sub menu item id string array.

-subMenu(-sm)booleanC Q E

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)intQ

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

-view(-v)stringC Q E

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

C Flag can appear in Create mode   E Flag can appear in Edit mode
Q Flag can appear in Query mode   M 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!'",
)