In Maya, I wanted to listConnections on a node and have it return the entire graph of its connections except for ones that traverse a set node in an effort to find clusters of disconnected nodes.
I ended up having to write a script to do this. Has anyone else attempted this or have any suggestions to make this better?
def FindDisconnectedCluster( node, nType ):
# List connections of node passed in
conNodes= [node]
conNodes += listConnections( conNodes, sh=True )
#Counts used to determine if list of nodes has grown after listing connections
count= 1
newCount= len(conNodes)
while newCount != count:
for conNode in conNodes:
# Prevent sets from being evaluated
if nodeType( conNode, i=True ).count('objectSet'):
conNodes.remove( conNode )
continue
#Verify all the nodes are of the current nType, just transforms or a set. If not, reset the conNodes list and bail.
if not nodeType( conNode, i=True ).count( nType ) and not nodeType( conNode, i=True ).count('transformGeometry') and not nodeType( conNode, i=True ).count('objectSet'):
return []
count = newCount
# Must get shapes to get the whole node graph
conNodes += listConnections( conNodes, sh=True )
# Make list a set and then a list again to remove duplicate nodes
conNodes = list(set(conNodes))
newCount = len(conNodes)
# Prevent sets from being returned
for conNode in conNodes:
if nodeType( conNode, i=True ).count('objectSet'):
conNodes.remove( conNode )
return conNodes