This is what I have for basically all nodes - but is GUI based
def listReadNodes(n=nuke.selectedNodes()): text='' result='' line=0 # sort out nodes to find if not n: nodes2use=nuke.allNodes() else: nodes2use=n # iterate through nodes and print the file path for n in nodes2use: if n.Class() in {'Read', 'ReadGeo2'}: line+=1 result+= str(line)+') '+n['name'].value()+' \t'+n['file'].value()+'\n' print >> sys.stderr, result return result r =listReadNodes() nuke.display("r", nuke.root(), "List of Read and ReadGeo Paths", 1500) > On 15 Feb 2016, at 07:27, Howard Jones <mrhowardjo...@yahoo.com> wrote: > > Out of interest can you just use nuke.allNodes('Read') and see if they have > an output and same for ReadGeo? > > Howard > >> On 14 Feb 2016, at 11:33 pm, Ben Dickson <ben.dick...@rsp.com.au> wrote: >> >> Your recursive tree walking is probably going over every possible >> combination of connections, when you only need to visit each node once >> (since once you have checked all upstream connections from one node, there's >> no need to check them again) >> >> This should be mostly equivalent to your "recursiveDependencies" method - >> mainly it is just quicker, but it also handles when a node is disabled (by >> only checking the primary pipe) >> >> def _get_upstream(starter, _visited=None): >> """Get upstream nodes, handling disabled nodes sensibly >> """ >> >> if _visited is None: >> _visited = set() >> >> elif starter in _visited: >> # If a node is already visisted, it's inputs have already been >> # inspected, so, skip. >> return >> >> yield starter >> >> if ('disable' in starter.knobs() >> and starter['disable'].value() >> and not starter['disable'].hasExpression() >> ): >> >> # Disabled permenantly (non-expression), >> # only look at first input >> first_input = starter.input(0) >> if first_input is None: >> # Node has no inputs (e.g empty Group with zero inputs) >> return # done >> else: >> for n in _get_upstream(first_input, _visited=_visited): >> _visited.add(n) >> yield n >> >> else: >> # Regular node, look at all upstream nodes >> inputs = starter.dependencies( >> nuke.HIDDEN_INPUTS|nuke.INPUTS|nuke.EXPRESSIONS) >> for curinp in inputs: >> for n in _get_upstream(curinp, _visited=_visited): >> _visited.add(n) >> yield n >> >> >>> On 13/02/16 08:49, J Bills wrote: >>> This might not be the most efficient, but we have this in place as part >>> of a larger archive script, happy to share: >>> >>> >>> >>> import nuke >>> import os >>> import sys >>> >>> >>> def recursiveDependencies(n): >>> '''Given a node, find all upstream nodes. This works, but for moderately >>> complex nuke graphs it can take a long long time, eg 516 nodes found in >>> 1418 seconds''' >>> thisDependencies = set(n.dependencies()) >>> if not thisDependencies: >>> return set() >>> dependencyDependencies = set() >>> for nn in thisDependencies: >>> dependencyDependencies.update(recursiveDependencies(nn)) >>> return thisDependencies.union(dependencyDependencies) >>> >>> def findOutputs(): >>> result = [] >>> for n in nuke.allNodes(): >>> if n.Class() in ["Write"]: >>> result.append(n) >>> return result >>> >>> def findInputsFromOutputs(): >>> result = set() >>> for n in findOutputs(): >>> dependencies = recursiveDependencies(n) >>> for dependent in dependencies: >>> if dependent.Class() in ['Read','ReadGeo']: >>> result.add(os.path.dirname(nuke.filename(dependent))) >>> return list(result) >>> >>> def printInputsFromOutputs(): >>> print '\n'.join(findInputsFromOutputs()) >>> >>> def findInputs(): >>> result = set() >>> for n in nuke.allNodes(): >>> if n.Class() in ["Read", "ReadGeo"]: >>> result.add(os.path.dirname(nuke.filename(n))) >>> result = list(result) >>> result.sort() >>> return result >>> >>> def printInputs(): >>> print '\n'.join(findInputs()) >>> >>> >>> >>> >>> On Thu, Feb 11, 2016 at 11:34 AM, Dan Stein >>> <daniel.st...@thefoundry.co.uk <mailto:daniel.st...@thefoundry.co.uk>> >>> wrote: >>> >>> For non-GUI you can load Nuke as a Python module. >>> >>> >>> http://docs.thefoundry.co.uk/nuke/80/pythondevguide/nuke_as_python_module.html >>> >>> Then just collect the Read and ReadGeo nodes however you would in >>> the GUI, nuke.allNodes('Read')... etc >>> >>> On Feb 11, 2016, at 10:52 AM, Gabor Hovanyi <hova...@gmail.com >>> <mailto:hova...@gmail.com>> wrote: >>> >>>> for reads, you could use nukescripts.get_script_data() or >>>> nukescripts.get_reads() >>>> >>>> -g >>>> >>>> On Thu, Feb 11, 2016 at 10:26 AM, Gary Jaeger <g...@corestudio.com >>>> <mailto:g...@corestudio.com>> wrote: >>>> >>>> Is there a way, preferably in non-gui mode, to quickly >>>> generate a list of all read nodes, including geo, used in a >>>> script? >>>> >>>> Gary Jaeger // Core Studio >>>> 249 Princeton Avenue >>>> Half Moon Bay, CA 94019 >>>> 650.728.7957 <tel:650.728.7957> (direct) >>>> 650.728.7060 <tel:650.728.7060> (main) >>>> http://corestudio.com <http://corestudio.com/> >>>> >>>> >>>> _______________________________________________ >>>> Nuke-users mailing list >>>> Nuke-users@support.thefoundry.co.uk >>>> <mailto:Nuke-users@support.thefoundry.co.uk>, >>>> http://forums.thefoundry.co.uk/ >>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users >>>> >>>> >>>> _______________________________________________ >>>> Nuke-users mailing list >>>> Nuke-users@support.thefoundry.co.uk >>>> <mailto:Nuke-users@support.thefoundry.co.uk>, >>>> http://forums.thefoundry.co.uk/ >>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users >>> >>> _______________________________________________ >>> Nuke-users mailing list >>> Nuke-users@support.thefoundry.co.uk >>> <mailto:Nuke-users@support.thefoundry.co.uk>, >>> http://forums.thefoundry.co.uk/ >>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users >>> >>> >>> >>> >>> _______________________________________________ >>> Nuke-users mailing list >>> Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ >>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users >> >> -- >> ben dickson >> 2D TD | ben.dick...@rsp.com.au >> rising sun pictures | www.rsp.com.au >> _______________________________________________ >> Nuke-users mailing list >> Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ >> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users _______________________________________________ Nuke-users mailing list Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users