Go to: Synopsis. Flags. Return value. Python examples.
setParent(
[parent]
, [defineTemplate=string], [menu=boolean], [query=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 editable.
This command changes the default parent to be the specified parent.
Two special parents are "/" which indicates the top of the
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.
defineTemplate, menu, query, topLevel, upLevel, useTemplate
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.
|
Name of the parent if the parent changes. Nothing if the parent
doesn't change.
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' )
Return to Autodesk Index