Go to: Synopsis. Return value. Flags. Python examples.

Synopsis

optionMenu( [string] , [alwaysCallChangeCommand=boolean], [annotation=string], [backgroundColor=[float, float, float]], [beforeShowPopup=script], [changeCommand=script], [defineTemplate=string], [deleteAllItems=boolean], [docTag=string], [dragCallback=script], [dropCallback=script], [enable=boolean], [enableBackground=boolean], [enableKeyboardFocus=boolean], [exists=boolean], [fullPathName=boolean], [height=int], [highlightColor=[float, float, float]], [isObscured=boolean], [itemListLong=boolean], [itemListShort=boolean], [label=string], [manage=boolean], [maxVisibleItems=int], [noBackground=boolean], [numberOfItems=boolean], [numberOfPopupMenus=boolean], [parent=string], [popupMenuArray=boolean], [postMenuCommand=script], [postMenuCommandOnce=boolean], [preventOverride=boolean], [select=int], [statusBarMessage=string], [useTemplate=string], [value=string], [visible=boolean], [visibleChangeCommand=script], [width=int])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

optionMenu is undoable, queryable, and editable.

This command creates a popup menu control. The command creates the control and provides its menu. Subsequent calls to the menuItem command will place them in the popup. Note that commands attached to menu items will not get called. Attach any commands via the -cc/changedCommand flag.

Return value

stringFull path name to the control.

In query mode, return type is based on queried flag.

Flags

alwaysCallChangeCommand, annotation, backgroundColor, beforeShowPopup, changeCommand, defineTemplate, deleteAllItems, docTag, dragCallback, dropCallback, enable, enableBackground, enableKeyboardFocus, exists, fullPathName, height, highlightColor, isObscured, itemListLong, itemListShort, label, manage, maxVisibleItems, noBackground, numberOfItems, numberOfPopupMenus, parent, popupMenuArray, postMenuCommand, postMenuCommandOnce, preventOverride, select, statusBarMessage, useTemplate, value, visible, visibleChangeCommand, width
Long name (short name) Argument types Properties
alwaysCallChangeCommand(acc) boolean createquery
Toggle whether to always call the change command, regardless of the change.
annotation(ann) string createqueryedit
Annotate the control with an extra string value.
backgroundColor(bgc) [float, float, float] createqueryedit
The background color of the control. The arguments correspond to the red, green, and blue color components. Each component ranges in value from 0.0 to 1.0.
When setting backgroundColor, the background is automatically enabled, unless enableBackground is also specified with a false value.
beforeShowPopup(bsp) script createedit
Callback that is called just before we show the drop down menu.
changeCommand(cc) script createedit
Adds a callback that is called when a new item is selected.

The MEL script will have the newly selected item's value substituted for #1.

For Python, the callback should be a callable object which accepts one argument, which is the newly selected item's value.

defineTemplate(dt) string create
Puts the command in a mode where any other flags and arguments are parsed and added to the command template specified in the argument. They will be used as default arguments in any subsequent invocations of the command when templateName is set as the current template.
deleteAllItems(dai) boolean edit
Delete all the items in this menu.
docTag(dtg) string createqueryedit
Add a documentation flag to the control. The documentation flag has a directory structure. (e.g., -dt render/multiLister/createNode/material)
dragCallback(dgc) script createedit
Adds a callback that is called when the middle mouse button is pressed. The MEL version of the callback is of the form:

global proc string[] callbackName(string $dragControl, int $x, int $y, int $mods)

The proc returns a string array that is transferred to the drop site. By convention the first string in the array describes the user settable message type. Controls that are application defined drag sources may ignore the callback. $mods allows testing for the key modifiers CTRL and SHIFT. Possible values are 0 == No modifiers, 1 == SHIFT, 2 == CTRL, 3 == CTRL + SHIFT.

In Python, it is similar, but there are two ways to specify the callback. The recommended way is to pass a Python function object as the argument. In that case, the Python callback should have the form:

def callbackName( dragControl, x, y, modifiers ):

The values of these arguments are the same as those for the MEL version above.

The other way to specify the callback in Python is to specify a string to be executed. In that case, the string will have the values substituted into it via the standard Python format operator. The format values are passed in a dictionary with the keys "dragControl", "x", "y", "modifiers". The "dragControl" value is a string and the other values are integers (eg the callback string could be "print '%(dragControl)s %(x)d %(y)d %(modifiers)d'")

dropCallback(dpc) script createedit
Adds a callback that is called when a drag and drop operation is released above the drop site. The MEL version of the callback is of the form:

global proc callbackName(string $dragControl, string $dropControl, string $msgs[], int $x, int $y, int $type)

The proc receives a string array that is transferred from the drag source. The first string in the msgs array describes the user defined message type. Controls that are application defined drop sites may ignore the callback. $type can have values of 1 == Move, 2 == Copy, 3 == Link.

In Python, it is similar, but there are two ways to specify the callback. The recommended way is to pass a Python function object as the argument. In that case, the Python callback should have the form:

def pythonDropTest( dragControl, dropControl, messages, x, y, dragType ):

The values of these arguments are the same as those for the MEL version above.

The other way to specify the callback in Python is to specify a string to be executed. In that case, the string will have the values substituted into it via the standard Python format operator. The format values are passed in a dictionary with the keys "dragControl", "dropControl", "messages", "x", "y", "type". The "dragControl" value is a string and the other values are integers (eg the callback string could be "print '%(dragControl)s %(dropControl)s %(messages)r %(x)d %(y)d %(type)d'")

enable(en) boolean createqueryedit
The enable state of the control. By default, this flag is set to true and the control is enabled. Specify false and the control will appear dimmed or greyed-out indicating it is disabled.
enableBackground(ebg) boolean createqueryedit
Enables the background color of the control.
enableKeyboardFocus(ekf) boolean createqueryedit
If enabled, the user can navigate to the control with the tab key and select values with the keyboard or mouse. This flag would typically be used to turn off focus support from controls that get it by default, like Edit and List controls If disabled, text in text fields can still be selected with the mouse but it cannot be copied (except in Linux when "Middle Click Paste" is enabled).
exists(ex) boolean create
Returns whether the specified object exists or not. Other flags are ignored.
fullPathName(fpn) boolean query
Return the full path name of the widget, which includes all the parents.
height(h) int createqueryedit
The height of the control. The control will attempt to be this size if it is not overruled by parent layout conditions.
highlightColor(hlc) [float, float, float] createqueryedit
The highlight color of the control. The arguments correspond to the red, green, and blue color components. Each component ranges in value from 0.0 to 1.0.
isObscured(io) boolean query
Return whether the control can actually be seen by the user. The control will be obscured if its state is invisible, if it is blocked (entirely or partially) by some other control, if it or a parent layout is unmanaged, or if the control's window is invisible or iconified.
itemListLong(ill) boolean query
The long names of the menu items.
itemListShort(ils) boolean query
The short names of the menu items.
label(l) string createqueryedit
The optional label text to the left of the popup menu.
manage(m) boolean createqueryedit
Manage state of the control. An unmanaged control is not visible, nor does it take up any screen real estate. All controls are created managed by default.
maxVisibleItems(mvi) int createqueryedit
The maximum number of items that are visible in the popup menu. If the popup contains more items than this, a scrollbar is added automatically.
noBackground(nbg) boolean createedit
Clear/reset the control's background. Passing true means the background should not be drawn at all, false means the background should be drawn. The state of this flag is inherited by children of this control.
numberOfItems(ni) boolean query
The number of menu items.
numberOfPopupMenus(npm) boolean query
Return the number of popup menus attached to this control.
parent(p) string createquery
The parent layout for this control.
popupMenuArray(pma) boolean query
Return the names of all the popup menus attached to this control.
postMenuCommand(pmc) script createedit
Specify a script to be executed when the popup menu is about to be shown.
postMenuCommandOnce(pmo) boolean createqueryedit
Indicate the -pmc/postMenuCommand should only be invoked once. Default value is false, ie. the -pmc/postMenuCommand is invoked every time the popup menu is shown.
preventOverride(po) boolean createqueryedit
If true, this flag prevents overriding the control's attribute via the control's right mouse button menu.
select(sl) int createqueryedit
The current menu item. The argument and return value is 1-based. Note that the current menu item can only be set if it is enabled.
statusBarMessage(sbm) string createedit
Extra string to display in the status bar when the mouse is over the control.
useTemplate(ut) string create
Forces the command to use a command template other than the current one.
value(v) string createqueryedit
The text of the current menu item.
visible(vis) boolean createqueryedit
The visible state of the control. A control is created visible by default. Note that a control's actual appearance is also dependent on the visible state of its parent layout(s).
visibleChangeCommand(vcc) script createqueryedit
Command that gets executed when visible state of the control changes.
width(w) int createqueryedit
The width of the control. The control will attempt to be this size if it is not overruled by parent layout conditions.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds

def printNewMenuItem( item ):
	print item

window = cmds.window()
cmds.columnLayout()
cmds.optionMenu( label='Colors', changeCommand=printNewMenuItem )
cmds.menuItem( label='Yellow' )
cmds.menuItem( label='Purple' )
cmds.menuItem( label='Orange' )
cmds.showWindow( window )