Is there a particular reason you don't want to pass the parent in explicitly? The following works:
import maya.cmds as cmds w1= cmds.window(menuBar=True,menuBarVisible=True) # default parent is now w1 cmds.columnLayout() cmds.text(l='window1') cmds.menu() # this gets added to w1 w2= cmds.window(menuBar=True,menuBarVisible=True) # default parent is now w2 cmds.columnLayout() cmds.text(l='window2') # set it back to w1 and add another menu # the following line fails cmds.menu(l='aaaaa', p=w1) cmds.showWindow(w1) cmds.showWindow(w2) I don't use defaults very much. I prefer to pass parents in explicitly so I can more easily restructure the ui as it evolves over time. For instance, inserting a new layout in between a an existing layout and the controls is a fairly common event. If you rely on the defaults then you have to move a lot of code around when you have this sort of change. I will generally create the layouts first to establish the structure, retain the return values of the creation commands, then add the controls. This allows me some flexibility when it comes to building the content of the uis because I don't have to worry about the creation order of the layouts. -Judah On Sat, Dec 19, 2009 at 5:01 PM, Chad Dombrova <[email protected]> wrote: > does anyone know if it is possible to set a default parent for top-level > menus? setParent() only sets the default parent for layouts and controls, > and setParent(menu=True) won't work when passed a window. > > here's some code to demonstrate my problem: > > import maya.cmds as cmds > w1= cmds.window(menuBar=True,menuBarVisible=True) > # default parent is now w1 > cmds.columnLayout() > cmds.text(l='window1') > cmds.menu() # this gets added to w1 > w2= cmds.window(menuBar=True,menuBarVisible=True) > # default parent is now w2 > cmds.columnLayout() > cmds.text(l='window2') > # set it back to w1 and add another menu > cmds.setParent(w1) > # the following line fails > cmds.menu() > cmds.showWindow(w1) > cmds.showWindow(w2) > > -chad > > > -- > http://groups.google.com/group/python_inside_maya -- http://groups.google.com/group/python_inside_maya
