Skip to content

Instantly share code, notes, and snippets.

@tokejepsen
Created March 31, 2016 10:27
Show Gist options
  • Save tokejepsen/974b9833897fe56e13722c85acfb999e to your computer and use it in GitHub Desktop.
Save tokejepsen/974b9833897fe56e13722c85acfb999e to your computer and use it in GitHub Desktop.
Maya: Closest Transform
import pymel.core as pm
def ctr_dist(objA, objB):
Ax, Ay, Az = objA.getRotatePivot(space="world")
Bx, By, Bz = objB.getRotatePivot(space="world")
return ((Ax-Bx)**2 + (Ay-By)**2 + (Az-Bz)**2 )**0.5
def get_closest_node(src, nodes):
dists = []
for node in nodes:
dists.append(ctr_dist(src, node))
index = dists.index(min(dists))
return nodes[index]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment