pymel.core.windows.setParent

static windows.setParent(*args, **kwargs)

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 setParentcommand (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/subMenumay also be treated as menu objects. The default parent is ignored by any object that explicitly sets the -p/parentflag when it is created.

Modifications
  • returns None object instead of the string ‘NONE’
Flags:
Long name (short name) Argument Types Properties
defineTemplate (dt) unicode ../../../_images/create.gif
 

Put a command in a mode where any other flags and args are parsed and added to the command template with the given name. They will be used as default arguments in any subsequent invocations of the command when templateName is set as the current template.

menu (m) bool ../../../_images/create.gif ../../../_images/query.gif
 
Parent menu for menu items.
topLevel (top) bool ../../../_images/create.gif
 
Move to the top level in the hierarchy. Equivalent to use /
upLevel (u) bool ../../../_images/create.gif
 
Move up one level in the hierarchy. Equivalent to use ..
useTemplate (ut) unicode ../../../_images/create.gif
 

Will force the command to use a command template given by the name other than the current one. Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.setParent

Example:

import pymel.core as pm

#  Create a window with a menu bar and two menu bar layouts.
#
window = pm.window(menuBar=True, widthHeight=(300, 200) )
fileMenu = pm.menu( label='File')
pm.menuItem( label='Open' )
# Result: ui.SubMenuItem('window1|menu38|menuItem416') #

pm.paneLayout( configuration='vertical2' )
# Result: ui.PaneLayout('window1|paneLayout7') #

leftMenuBarLayout = pm.menuBarLayout()
leftMenu = pm.menu( label='Left' )
pm.menuItem( label='One' )
# Result: ui.SubMenuItem('window1|paneLayout7|menuBarLayout2|menu39|menuItem417') #
pm.setParent( '..' )
# Result: u'window1|paneLayout7' #

pm.menuBarLayout()
# Result: ui.MenuBarLayout('window1|paneLayout7|menuBarLayout3') #
pm.menu( label='Right' )
# Result: ui.Menu('window1|paneLayout7|menuBarLayout3|menu40') #
rightSubMenu = pm.menuItem(subMenu=True, label='Colors' )
pm.setParent( '..' )
# Result: u'window1|paneLayout7' #
pm.showWindow( window )

#  Add item to the "File" menu.
#
pm.setParent( fileMenu, menu=True )
# Result: u'window1|menu38' #
pm.menuItem( label='Save' )
# Result: ui.SubMenuItem('window1|menu38|menuItem419') #

#  Add item to the "Left" menu, explicitly ignore default parent
#    by setting -p/parent flag.
#
pm.menuItem( parent=leftMenu, label='Two' )
# Result: ui.SubMenuItem('window1|paneLayout7|menuBarLayout2|menu39|menuItem420') #

#  Add more items to the "File" menu because it is still the
#    default parent.
#
pm.menuItem( divider=True )
# Result: ui.SubMenuItem('window1|menu38|menuItem421') #
pm.menuItem( label='Close' )
# Result: ui.SubMenuItem('window1|menu38|menuItem422') #

#  Add another menu to the left menu bar layout.
#
pm.setParent( leftMenuBarLayout )
# Result: u'window1|paneLayout7|menuBarLayout2' #
pm.menu( label='Middle' )
# Result: ui.Menu('window1|paneLayout7|menuBarLayout2|menu41') #
pm.menuItem( label='Three' )
# Result: ui.SubMenuItem('window1|paneLayout7|menuBarLayout2|menu41|menuItem423') #

#  Add items to right sub menu.
#
pm.setParent( rightSubMenu, menu=True )
# Result: u'window1|paneLayout7|menuBarLayout3|menu40|menuItem418' #
pm.menuItem( label='Red' )
# Result: ui.SubMenuItem('window1|paneLayout7|menuBarLayout3|menu40|menuItem418|menuItem424') #
pm.menuItem( label='Blue' )
# Result: ui.SubMenuItem('window1|paneLayout7|menuBarLayout3|menu40|menuItem418|menuItem425') #
pm.menuItem( label='Green' )
# Result: ui.SubMenuItem('window1|paneLayout7|menuBarLayout3|menu40|menuItem418|menuItem426') #

Previous topic

pymel.core.windows.setNodeTypeFlag

Next topic

pymel.core.windows.setStartupMessage

Core

Core Modules

Other Modules

This Page