Been wondering about the opposite case for this one lately but think the same 
applies.  My pondering relates to the lack of an "ancestor" terminology in 
Maya, listRelatives is a command to query childs and parents and although 
listRelatives has an allParents keyword I can't find any notion of ancestry 
beyond the nearest family.

  Threw this together in order to get the full "family" tree but am aware of 
two cases it doesn't fully list all relatives,you could potentially switch out 
the parent keyword for children and it should traverse downwards instead.

def get_ancestors( node , checked=None ):
    """Returns all connected ancestors of a given node"""

    if not checked:
        checked = []
    ancestors = []
    checked.append( node )
    parents = maya.cmds.listRelatives( node , ap=True)
    if parents:
        for parent in parents:
            if parent not in checked:
                checked.append( parent )
                ancestors.append( parent )
                ancestors += get_ancestors( parent , checked=checked )
   
    return ancestors
    
print get_ancestors( node )


  Just a simple recursive function, something that keeps calling itself until 
the job is done, but I iterate this example I'm copy pasting off my notes app 
is not doing the full job so you will need to expand on it a little.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to