Connection Hierarchy

Just a quick recursing utility function to get all the nodes in a connected hierarchy

def getConnectionHierarchy(sourceNode, delList):
     try:
         nextConn = list(set(cmds.listConnections(sourceNode, s = True, d = False)))
         #print "NEXT CONN: "
         #print nextConn
         
         #print len(nextConn)
         if len(nextConn) > 0:
             nextNode = nextConn[0]
             if cmds.objExists(nextNode):
                 #print "NEXT NODE: "
                 #print nextNode
                 delList.append(nextNode)
                 getConnectionHierarchy(nextNode, delList)
                 
     except TypeError:
         print "No more!"
     finally:
         return delList

Leave a Reply

Your email address will not be published. Required fields are marked *