If you just need to find the nodes, there’s no reason to select them. Here’s a 
quick function that will walk up the tree (and into groups) and give you back a 
set containing all the Read nodes upstream of the input node (selectedNode() if 
nothing is passed).

def recursiveFindReads(node=None, group=nuke.root(), reads=None):
    if reads is None:
        reads = set()
    if node is None:
        node = nuke.selectedNode() # Let this error on purpose if no node 
selected
    for n in node.dependencies(nuke.INPUTS | nuke.HIDDEN_INPUTS):
        cls = n.Class()
        if cls == 'Read':
            reads.add(n)
        elif cls == 'Group':
            reads = reads.union(recursiveFindReads(node=[x for x in n.nodes() 
if x.Class() == 'Output'][0], group=n, reads=reads))
        else:
            reads = reads.union(recursiveFindReads(node=n, group=group, 
reads=reads))
    return reads


-Nathan



From: Christopher Horvath 
Sent: Thursday, April 26, 2012 7:16 PM
To: nuke-python@support.thefoundry.co.uk 
Subject: Re: [Nuke-python] selecting a node from its name

One more thing - you should probably check to make sure the selected node is 
not None!

if selectedNode != None:
    # do the rest


On Thu, Apr 26, 2012 at 7:15 PM, Christopher Horvath <blackenc...@gmail.com> 
wrote:

  try this:
  #############################
  # Get selected node
  selectedNode = nuke.selectedNode()


  # If you want to de-select this guy...
  selectedNode.setSelected( False )


  # Loop! Don't grab the dependent nodes each time, just do it once.
  depNodes = selectedNode.dependencies()
  for depNode in depNodes:
      depNode.setSelected( True )


  # All done!
  #######################


  On Thu, Apr 26, 2012 at 7:08 PM, invisfx <nuke-python-re...@thefoundry.co.uk> 
wrote:

    what I am trying to do is write a script that finds all the read nodes 
above a selected node in the graph.
    so what I figure I have to do is 
    get the dependencies of a node and loop through testing if they are a read 
node and continue recursively 

    for a in nuke.selectedNode().dependencies():
    name = a.name()
    for n in name:
    select n:
    if n.Class() == ?Read?:

    but I don't know how to select a node from its name
    can someone please help? I will accept any suggestions on how to make this 
easier as well!
    Thanks

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






  -- 
  I think this situation absolutely requires that a really futile and stupid 
gesture be done on somebody's part. And we're just the guys to do it.





-- 
I think this situation absolutely requires that a really futile and stupid 
gesture be done on somebody's part. And we're just the guys to do it.



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

Reply via email to