Last active
June 18, 2019 21:12
-
-
Save jedypod/393ba6191bcc668830c10b52ad07c36b to your computer and use it in GitHub Desktop.
Nuke Python Recipes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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