Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Nuke Python Recipes
import nuke, math
def get_closest_node(node):
# Return the closest node to node
distances = {}
for n in nuke.allNodes():
if ==
distance = math.sqrt(
math.pow( (node.xpos() - n.xpos()), 2 ) + math.pow( (node.ypos() - n.ypos()), 2 )
distances[] = distance
return nuke.toNode(min(distances, key=distances.get))
if __name__=="__main__":
for node in nuke.selectedNodes():
closest = get_closest_node(node)
print "{0} : {1}".format(,
node.setInput(0, closest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.