pythonmaya

List top Nodes / siblings in maya outliner


Is there a way to only list top nodes in the outliner, without traversing all the depths?

import maya.cmds as cmds
cmds.listRelatives("master", noIntermediate=True)

I was kind of expecting that there will be a key like world to search the topnodes in the outliner.

Example Outliner:

#--- pSphere1
#---group1
 ------box1
#pSphere2

I only want pSphere1, pSphere2 and group1 not the children of those.


Solution

  • What you're looking for is this:

    cmds.ls(assemblies=True)

    With your example, it will return the following: [u'persp', u'top', u'front', u'side', u'pSphere1', u'group1', u'pSphere2']

    You can filter out the cameras either by name, their object type (camera), or using cmds.camera to determine if it's a default camera:

    cmds.camera("front", q=True, startupCamera=True) # Would return True.