DAG walking isn’t slow if your algorithm is well-written, and it’s really the only solution for pairing output paths with sets of input dependencies. I use it in conjunction with some group flattening logic to gather dependency tracking information from scripts.

Here's a basic generator for depth-first traversal:

def iterDependencies(node):
   mask = nuke.INPUTS | nuke.HIDDEN_INPUTS
   stack = node.dependencies(mask)
   seen = set()
   while stack:
       node = stack.pop()
       if node in seen:
           continue
       yield node
       seen.add(node)
       stack.extend(node.dependencies(mask))

Implementing a solution outside of Nuke is possible as well, but because Nuke writes knob values sparsely, you have to provide one important piece of information yourself: The default number of inputs a given node class has. Once you have that, it’s relatively simple to parse a Nuke script in the same stack-based manner Nuke does and rebuild a DAG in whatever format you’d like. Honestly, though, it would be much simpler to just use the nuke module directly as Ivan suggests.

-Nathan



From: Jep Hill
Sent: Sunday, January 26, 2014 12:25 PM
To: [email protected]
Subject: [Nuke-python] [nuke -t] oddness when opening scripts witherrorsininteractive mode

Thanks for checking me on this guys. Ivan, I am getting the same print out now... the runtime exception does indeed work. I realized I hadn't tested it properly -- DERP.

the "print nuke.allNodes()" was just a quick test call I threw in there -- in my code, I was actually running a block that included "nuke.selectConnectedNodes()" -- that spits out an unbelievable amount of junk when run on a script with "issues" -- any one know how to suppress all that garbage when run via shell? We should be able to run that in "quiet" mode.

Ivan, can you confirm you're getting the same behavior with nuke.selectConnectedNodes when running your "gizmos missing" script through something like:

##### process2.py ########## import nuke import os def main(): nk = os.path.abspath(sys.argv[1]) try: nuke.scriptOpen(nk) except RuntimeError: print "A RuntimeError occurred: Ignoring..." pass # Moving on... activeWrites = [ x['selected'].setValue(True) for x in nuke.allNodes('Write') if not x['disable'].value() ] if activeWrites: nuke.selectConnectedNodes() files = list(set([ x['file'].value() for x in nuke.selectedNodes('Read') ])) print "\n%s\n" % '\n'.join(files)if __name__ == '__main__': main() ######################

nuke -t process2.py missing_gizmos.nk
It may be that this behavior is just inherent with the nuke.selectConnectedNdoes method -- the larger issue I'm looking to solve (lot's of posts on this issue -- not sure what the latest conventional wisdom is as of 2014) Basically, I'd like to optimize selectConnectedNodes to be able to find out the files *actually used* by the active (non-disabled) write nodes to replace a "tree walker" which is very slow. Ultimately I'd like to implement a solution OUTSIDE of nuke that just parses the script file however, the .nk file leaves no clues (that I've found) that would suggest which Read nodes are actually used in any of the script trees. Since a shell based parse doesn't seem to be an option, and python seems overly slow, perhaps C++ is a better route to take?
Thanks again...
Cheers,Jep


_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to