pymel.core.windows.setParent

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 appear in Create mode of commandFlag 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

import maya.cmds as cmds

#  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.CommandMenuItem('window1|menu67|menuItem932') #

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

leftMenuBarLayout = pm.menuBarLayout()
leftMenu = pm.menu( label='Left' )
pm.menuItem( label='One' )
# Result: ui.CommandMenuItem('window1|paneLayout15|menuBarLayout4|menu68|menuItem933') #
pm.setParent( '..' )
# Result: u'window1|paneLayout15' #

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

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

#  Add item to the "Left" menu, explicitly ignore default parent
#    by setting -p/parent flag.
#
pm.menuItem( parent=leftMenu, label='Two' )
# Result: ui.CommandMenuItem('window1|paneLayout15|menuBarLayout4|menu68|menuItem936') #

#  Add more items to the "File" menu because it is still the
#    default parent.
#
pm.menuItem( divider=True )
# Result: ui.CommandMenuItem('window1|menu67|menuItem937') #
pm.menuItem( label='Close' )
# Result: ui.CommandMenuItem('window1|menu67|menuItem938') #

#  Add another menu to the left menu bar layout.
#
pm.setParent( leftMenuBarLayout )
# Result: u'window1|paneLayout15|menuBarLayout4' #
pm.menu( label='Middle' )
# Result: ui.Menu('window1|paneLayout15|menuBarLayout4|menu70') #
pm.menuItem( label='Three' )
# Result: ui.CommandMenuItem('window1|paneLayout15|menuBarLayout4|menu70|menuItem939') #

#  Add items to right sub menu.
#
pm.setParent( rightSubMenu, menu=True )
# Result: u'window1|paneLayout15|menuBarLayout5|menu69|menuItem934' #
pm.menuItem( label='Red' )
# Result: ui.CommandMenuItem('window1|paneLayout15|menuBarLayout5|menu69|menuItem934|menuItem940') #
pm.menuItem( label='Blue' )
# Result: ui.CommandMenuItem('window1|paneLayout15|menuBarLayout5|menu69|menuItem934|menuItem941') #
pm.menuItem( label='Green' )
# Result: ui.CommandMenuItem('window1|paneLayout15|menuBarLayout5|menu69|menuItem934|menuItem942') #

Previous topic

pymel.core.windows.setNodeTypeFlag

Next topic

pymel.core.windows.setStartupMessage

Core

Core Modules

Other Modules

This Page