Go to: Synopsis. Return value. Flags. Python examples.
setParent(
[string]
, [defineTemplate=string], [menu=boolean], [topLevel=boolean], [upLevel=boolean], [useTemplate=string])
Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.
setParent is undoable, queryable, and NOT editable.
This command changes the default parent to be the specified parent. Two special parents are "|" which indicates the top level layout of the window hierarchy, or ".." which indicates one level up in the hierarchy. Trying to move above the top level has no effect.
A control must be parented to a control layout. A control layout may be parented to another control layout or a window. A menu may be parented to a window or a menu bar layout. For all of these cases the setParent command (with no flags) will indicate the current default parent.
A menu item must be parented to a menu. To specify the default menu parent use the command setParent -m/menu. Note that all menu item objects created using the -sm/subMenu may also be treated as menu objects.
The default parent is ignored by any object that explicitly sets the -p/parent flag when it is created.
string | Name of the parent if the parent changes. Empty string if the parent doesn't change. |
In query mode, return type is based on queried flag.
Long name (short name) | Argument types | Properties | ||
---|---|---|---|---|
defineTemplate(dt)
|
string
|
![]() |
||
|
||||
menu(m)
|
boolean
|
![]() ![]() |
||
|
||||
topLevel(top)
|
boolean
|
![]() |
||
|
||||
upLevel(u)
|
boolean
|
![]() |
||
|
||||
useTemplate(ut)
|
string
|
![]() |
||
|
![]() |
![]() |
![]() |
![]() |
import maya.cmds as cmds # Create a window with a menu bar and two menu bar layouts. # window = cmds.window(menuBar=True, widthHeight=(300, 200) ) fileMenu = cmds.menu( label='File') cmds.menuItem( label='Open' ) cmds.paneLayout( configuration='vertical2' ) leftMenuBarLayout = cmds.menuBarLayout() leftMenu = cmds.menu( label='Left' ) cmds.menuItem( label='One' ) cmds.setParent( '..' ) cmds.menuBarLayout() cmds.menu( label='Right' ) rightSubMenu = cmds.menuItem(subMenu=True, label='Colors' ) cmds.setParent( '..' ) cmds.showWindow( window ) # Add item to the "File" menu. # cmds.setParent( fileMenu, menu=True ) cmds.menuItem( label='Save' ) # Add item to the "Left" menu, explicitly ignore default parent # by setting -p/parent flag. # cmds.menuItem( parent=leftMenu, label='Two' ) # Add more items to the "File" menu because it is still the # default parent. # cmds.menuItem( divider=True ) cmds.menuItem( label='Close' ) # Add another menu to the left menu bar layout. # cmds.setParent( leftMenuBarLayout ) cmds.menu( label='Middle' ) cmds.menuItem( label='Three' ) # Add items to right sub menu. # cmds.setParent( rightSubMenu, menu=True ) cmds.menuItem( label='Red' ) cmds.menuItem( label='Blue' ) cmds.menuItem( label='Green' )