Update: This is a perfect example of overengineering ;) I did all the below work before I realized there is a
Say you have a list of Maya materials, and you want to find all the place2dTexture nodes connected to them.
listHistory
node, which does all this for you. Check it out...Say you have a list of Maya materials, and you want to find all the place2dTexture nodes connected to them.
# Python code import maya.cmds as mc def allIncomingConnections(nodes, nodeType=None): """ Based on the nodes, find all incoming connections, and return them. This will recursively search through all incoming connections of all inputs. nodes : string or list : of nodes to find all incoming connections on. nodeType : None, string, list : Optional, will filter the result by these types of nodes. return : list : Nodes found """ ret = [] # Convert our args to lists if they were passed in as strings: if type(nodes) == type(""): nodes = [nodes] if nodeType is not None: if type(nodeType) == type(""): nodeType = [nodeType] for n in nodes: incoming = mc.listConnections(n, source=True, destination=False) if incoming is not None: for i in incoming: if nodeType is not None: if mc.objectType(i) in nodeType: ret.append(i) else: ret.append(i) nodes.append(i) # remove dupes: ret = list(set(ret)) return retExample:
incoming = allIncomingConnections("myMaterial", "place2dTexture") print incoming # [u'place2dTexture643', u'place2dTexture642', u'place2dTexture641']