命令 (MEL/Python)
|
MGPickerMenu
|
跳转到: 概要. MEL例子. Python例子.
概要
MGPickerMenu (menuIDString, [addMenuItem=(string, string, string, string, string)], [copyMenu=boolean], [copyPairedMenu=boolean], [deleteAllItems=boolean], [exist=boolean], [itemArray=boolean], [insertMenuItem=(int, string, string, string, string, string)], [mode=string], [menuItem=int], [markingMenu=boolean],[numberOfItems=boolean],[parent=string],[popOutsideBBox=boolean], [useRightMenu=boolean], [view=string])
MGPickerMenu 不可撤消, 可以查询且可以编辑。
你不需要创建菜单,因为对于每一个picker对象来讲,已经有左键右键菜单(只是初始是空的,看起来像没有),你需要做的只是查询和编辑它。
你仍可在创建模式下使用该命令,不过它只是帮你获取相应的菜单id罢了。
在查询和编辑模式下,一定要提供菜单id。菜单id的格式是这样的:
commandButton1.rightmenu //Picker按钮"commandButton1"的右键菜单的id.
selectButton1.leftmenu //Picker按钮"commandButton1"的左键菜单的id.
在编辑模式下,一些编辑性的flag会互相排斥,只会执行第一个就返回结果。
长名 (短名)
|
参数类型
|
属性
|
-addMenuItem(-ami)
|
string string string script string
|
 
|
|
只能用于编辑模式或创建模式,添加一个子菜单项。需要指定标签,图标路径,命令语言("mel" 或 "python"), 命令 及 marking菜单的方向 ("N", "NW", "W", "SW", "S", "SE", "E" or "NE").
* 要注意的是,即使该标签被用在创建模式,它返回的也是新加入的子菜单的id,而不是菜单本身的id。
|
|
-copyMenu(-cm)
|
string
|
 
|
|
只能用于编辑模式,用来从指定菜单id中复制所有内容到该菜单中。
|
|
-copyPairedMenu(-cpm)
|
|
 
|
|
只能用于编辑模式,用来从成对的菜单中复制所有内容到该菜单中。如从左键菜单复制内容到右键菜单,从右键菜单中复制内容到左键菜单。
|
|
-deleteAllItems(-dai)
|
|
 
|
|
-exist(-ex)
|
|

|
|
-itemArray(-ia)
|
|

|
|
只能用于查询模式, 返回所有子菜单的id字符窜数组。
|
|
-insertMenuItem(-imi)
|
int string string string script string
|
 
|
|
只能用于编辑模式或创建模式,用来在特定的索引处插入一个子菜单项。需要指定索引,标签,图标路径,命令语言("mel" 或 "python"), 命令 及 marking菜单的方向 ("N", "NW", "W", "SW", "S", "SE", "E" or "NE").
* 要注意的是,即使该标签被用在创建模式,它返回的也是新加入的子菜单的id,而不是菜单本身的id。
|
|
-mode(-m)
|
string
|
 
|
|
在查询模式下返回该菜单id属性右键还是左键菜单。在创建模式下,这个标签是必须的,用来指定你要获取的是右键的还是左键菜单id。(创建模式下-parent标签也是必须的)
|
|
-menuItem(-mi)
|
int
|

|
|
只能用于查询模式, 返回在特定索引值的子菜单的id字符窜。
|
|
-markingMenu(-mm)
|
boolean
|
  
|
|
查询或编辑菜单是否是一个marking menu。
|
|
-numberOfItems(-ni)
|
|

|
|
-parent(-p)
|
string
|
 
|
|
在查询模式下返回该菜单所属的picker对象id。在创建模式下,这个标签是必须的,用来指定你要获取的是哪个picker对象的菜单id。(创建模式下-mode 标签也是必须的)
|
|
-popOutsideBBox(-pob) 
|
boolean
|
  
|
|
决定菜单是在鼠标点击处弹出,还是在对象的形状矩形框外弹出。比如你把一个命令按钮作为菜单栏的菜单,点击时你会希望菜单在命令按钮下方弹出而不是在鼠标点击处。
默认值为False, 即在鼠标点击处弹出菜单。
|
|
-useRightMenu(-urm)
|
boolean
|
  
|
|
决定是否左键菜单要完全使用右键菜单的内容。对于本来就是右键菜单则编辑无效,因为右键菜单的这个值永远是true。
|
|
-view(-v)
|
string
|
  
|
|
决定你要查询哪个picker视图的菜单。要指定一个合法的视图id。
|
|
|
|
|
|
|
|
标签可以在创建模式中使用
|
标签可以在编辑模式中使用
|
标签可以在查询模式中使用
|
标签可以在一条命令中多次使用
|
MEL例子
// 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.
// 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 scene in order to test these codes.
# To form a picker menu id, use pickerItemId.leftmenu / pickerItemId.rightmenu
cmdButton = 'commandButton1'
rightMenu = mgp.MGPickerMenu(p=cmdButton, mode='rightmenu') # This just retrieves the id "commandButton1.rightmenu" instead of creating it.
# 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!
|