View Full Version : How to find the child node?

05-03-2011, 05:25 AM
Hi guys,
Sorry, I'm sure this is dead easy but I just cant seam to find a way to do it.

I need to find the child of a node. By child, I mean the node that has been linked to the parent
I'm a Max user so I'm probably not explaining that correctly... So heres what I do.

Create two polyCubes, pCube1 and pCube2.
Then in Hypergraph middle click hold and drag pCube2 over to pCube1 so that it is linked to pCube 1.
pCube2 is a child of pCube1

When I try listRelatives on pCube1 I get an array containing pCube2 and some of its relatives such as pCubeShape1 etc. Also, I cant just grab a particular index of the array because if joints are used in place of pCubes then the index of the real child(pCube2) changes.

How do I find pCube2 from pCube1?

I also tried pickWalk but that seams to only go from pCube1 to pCubeShape1


05-03-2011, 05:48 AM
This is how I'm doing it at the moment.

import maya.cmds as cmds
allSelectedObjects = cmds.ls(selection=True)
for node in allSelectedObjects:
allChildren = cmds.listRelatives(node)
allStupidChildren = cmds.listRelatives(node, shapes=True)
if allStupidChildren != None:
allRealChildren = list(set(allChildren) - set(allStupidChildren))
allRealChildren = allChildren
print allRealChildren

I'm sure theres an easier way.

05-03-2011, 08:43 AM
If I understand correctly, then you want to do the following:

select an object
find all childs of this object hierarchy
but ignore shape nodes
If yes, then this can be helpful:

import maya.cmds as cmds
myObject = "topNodeOfTheHierarchyOrWhateverYouWant"
cmds.select(myObject, hi=True)
transformNodes = cmds.ls(sl=True, type="transform")
print transformNodes

05-03-2011, 09:21 AM
Just use the listRelatives command. Without the -ad flag it'll give you only the children, with the ad flag it will give you all descendents. You can also throw in a type='transform' flag if you want to avoid getting the shape nodes back.

05-04-2011, 02:31 AM
Thanks Mark,
the type='transform' did the job...

CGTalk Moderation
05-04-2011, 02:31 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.