Skip to content

Instantly share code, notes, and snippets.

@jedypod
Last active June 18, 2019 21:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedypod/393ba6191bcc668830c10b52ad07c36b to your computer and use it in GitHub Desktop.
Save jedypod/393ba6191bcc668830c10b52ad07c36b to your computer and use it in GitHub Desktop.
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