Skip to content

Instantly share code, notes, and snippets.

Embed
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 n.name() == node.name():
continue
distance = math.sqrt(
math.pow( (node.xpos() - n.xpos()), 2 ) + math.pow( (node.ypos() - n.ypos()), 2 )
)
distances[n.name()] = 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.name(), closest.name())
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.