Search code examples
pythonnuke

Is there a way to zoom into the next node in the 'setSelected' list?


In The Foundry NukeX I'm trying to find list of nodes of same kind and zoom into each node one after the other of the .setSelected nodes.

To be clear I'm trying to create a Python code thats behind Edit -> Search... menu or hotkey / in NUKE.

With the below script it only zooms into the first node of the .setSelected list.

Is there a way to increment the zoom to next set of nodes every time I execute this code?

for w in nuke.allNodes('Transform'):
    w.setSelected(True)
    xC = w.xpos + w.screenWidth()/2
    yC = w.ypos + w.screenHeight()/2
    nuke.zoom(3, [xC, yC])

Solution

  • You need a nested for-in loop to make iterations inside a desired class.

    Here's a how your code should look like:

    import nuke
    
    for node in nuke.allNodes('Grade'):
        node.setSelected(True)
    
        for id in nuke.selectedNodes():
            xCoord = id.xpos() + id.screenWidth()/2
            yCoord = id.ypos() + id.screenHeight()/2
            nuke.zoom(5, [xCoord, yCoord])
    

    enter image description here