Hi, I'm having a problem figuring out how to get a list of all the nodes which will be exported when doing an export selection.
I'm pretty sure the rules (given the default settings) for it are:
1) Anything that's selected
2) Anything that's in the direct parent chain of selected dag objects
3) Any children of selected dag objects
4) Any shadingEngines which the above dag objects are connected to
5) All upstream nodes connected to the above (recursively)
1-4 are trivial using ls, listRelatives, and listConnections
The one I'm having a problem with is 5. I've tried a couple of things - first a while loop which lists all incoming nodes to the nodes in a list (starting with the ones gotten in steps 1-4) as long as new incoming nodes are found. The script looks something like this:
import maya.cmds as m
import maya.mel as mel
...
perform steps 1-4 and store in a list called allNodes
...
newNodes = allNodes
while len(newNodes):
newNodesTemp = m.listConnections (newNodes, s=1, d=0)
newNodes = []
if newNodesTemp:
for node in newNodesTemp:
if node not in allNodes: # necessary to avoid cyclic dependency freeze
allNodes.append(node)
newNodes.append(node)
This works, but as you can see, it's almost exponential in time, since each new node needs to go through the list of what has been "graphed" so far to know if it should be added, which becomes ridiculously slow on large scenes.
I also tried using the hyperShade -listUpstreamNodes (mel only it seems), but that only accepts one object at a time, and is probably even slower (it seemed slower, but I didn't time the two methods back to back).
I guess I could try other methods to get the inputs, geared more towards the settings in the export (history, expressions, channels, shaders, constraints), but I wouldn't be sure it would catch all, the only safe way is to get the entire input graph.
Is there any other way to check what would be exported given a selection?
Thanks in advance for any help.