MGPickerMenu命令

MGPickerMenu 不可撤消, 可以查询且可以编辑。

你不需要创建菜单,因为对于每一个picker对象来讲,已经有左键右键菜单(只是初始是空的,看起来像没有),你需要做的只是查询和编辑它。

你仍可在创建模式下使用该命令,不过它只是帮你获取相应的菜单id罢了。

在查询和编辑模式下,一定要提供菜单id。菜单id的格式是这样的:

"commandButton1.rightmenu "    #The right click menu for the picker item "commandButton1"
"selectButton1.leftmenu"       #The left click menu for the picker item "selectButton1"

在编辑模式下,一些编辑性的flag会互相排斥,只会执行第一个就返回结果。

跳转到: [MEL例子] [Python例子]

MGPickerMenu命令

-addMenuItem(-ami)string string string string stringC E

只能用于编辑模式或创建模式,添加一个子菜单项。

需要指定标签,图标路径,命令语言(melpython), 命令 及 marking菜单的方向 (N, NW, W, SW, S, SE, E or NE).

  • 要注意的是,即使该标签被用在创建模式,它返回的也是新加入的子菜单的id,而不是菜单本身的id。

-copyMenu(-cm)stringC E

只能用于编辑模式,用来从指定菜单id中复制所有内容到该菜单中。

-copyPairedMenu(-cpm)C E

只能用于编辑模式,用来从成对的菜单中复制所有内容到该菜单中。如从左键菜单复制内容到右键菜单,从右键菜单中复制内容到左键菜单。

-deleteAllItems(-dai)C E

只能用于编辑模式,清空菜单的内容。

-exist(-ex)Q

只能用于查询模式, 是否菜单id存在。

-itemArray(-ia)Q

只能用于查询模式, 返回所有子菜单的id字符窜数组。

-insertMenuItem(-imi)int string string string string stringC E

只能用于编辑模式或创建模式,用来在特定的索引处插入一个子菜单项。

需要指定索引,标签,图标路径,命令语言(melpython), 命令 及 marking菜单的方向 (N, NW, W, SW, S, SE, E or NE).

  • 要注意的是,即使该标签被用在创建模式,它返回的也是新加入的子菜单的id,而不是菜单本身的id。

-mode(-m)stringC Q

在查询模式下返回该菜单id属性右键还是左键菜单。在创建模式下,这个标签是必须的,用来指定你要获取的是右键的还是左键菜单id。(创建模式下-parent标签也是必须的)

-menuItem(-mi)intQ

只能用于查询模式, 返回在特定索引值的子菜单的id字符窜。

-markingMenu(-mm)booleanC Q E

查询或编辑菜单是否是一个marking menu。

-numberOfItems(-ni)Q

查询子菜单的数目。

-parent(-p)stringC Q

在查询模式下返回该菜单所属的picker对象id。在创建模式下,这个标签是必须的,用来指定你要获取的是哪个picker对象的菜单id。(创建模式下-mode 标签也是必须的)

-popOutsideBBox(-pob)booleanC Q E

决定菜单是在鼠标点击处弹出,还是在对象的形状矩形框外弹出。

比如你把一个命令按钮作为菜单栏的菜单,点击时你会希望菜单在命令按钮下方弹出而不是在鼠标点击处。

默认值为False, 即在鼠标点击处弹出菜单。

-useRightMenu(-urm)booleanC Q E

决定是否左键菜单要完全使用右键菜单的内容。对于本来就是右键菜单则编辑无效,因为右键菜单的这个值永远是true。

For right click menu, in edit mode this flag has no effect, in query mode, this flag always return true.

-view(-v)stringC Q E

决定你要查询哪个picker视图的菜单。要指定一个合法的视图id。

C 标签可以在创建模式中使用; E 标签可以在编辑模式中使用
Q 标签可以在查询模式中使用   M 标签可以在一条命令中多次使用.

MEL例子

// 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"`;
 
// Add / Insert a menu item:
string $menuItem1 = `MGPickerMenu -e 
      -addMenuItem "First Menu Item" "/path/to/icon0.png" "mel" "print \"It works!\"" "N" 
      $rightMenu`;
string $menuItem3 = `MGPickerMenu -e 
      -addMenuItem "Third Menu Item" "/path/to/icon2.png" "python" "print 'It works!'" "S" 
      $rightMenu`;
string $menuItem2 = `MGPickerMenu -e 
      -insertMenuItem 1 "Second Menu Item" "/path/to/icon1.png" "python" "print 'It inserts!'" "E" 
      $rightMenu`;

// Now you can test right click on commandButton1 using preview tool, see menu pops up!
 
// Let's continue to toggle on the marking menu state of the menu.
MGPickerMenu -e -markingMenu 1 $rightMenu;
// Now you can test right click on commandButton1 using preview tool, see marking menu pops up!

Python例子

from mgpicker import mgp

# You must make sure the picker item: commandButton1 is already in scenet.
# 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")

#  Add / Insert a menu item:
menuItem1 = mgp.MGPickerMenu(
    rightMenu,
    e=True,
    addMenuItem=(
        "First Menu Item",
        "/path/to/icon0.png",
        "mel",
        'print "It works!"',
        "N",
    ),
)
menuItem3 = mgp.MGPickerMenu(
    rightMenu,
    e=True,
    addMenuItem=(
        "Third Menu Item",
        "/path/to/icon2.png",
        "python",
        'print "It works!"',
        "S",
    ),
)
menuItem2 = mgp.MGPickerMenu(
    rightMenu,
    e=True,
    insertMenuItem=(
        1,
        "Second Menu Item",
        "/path/to/icon1.png",
        "python",
        'print "It inserts!"',
        "E",
    ),
)

# Now you can test right click on commandButton1 using preview tool, see menu pops up!

# Let's continue to toggle on the marking menu state of the menu.
mgp.MGPickerMenu(rightMenu, e=True, markingMenu=True)
# Now you can test right click on commandButton1 using preview tool, see marking menu pops up!