Here I'm using a tuple (made from the object's XYZ position) as a key, and the object's name as a value. The dictionary doesn't permit duplicate keys, so we filter out all duplicate objects. The dictionary is then returned as a list of values (object names). Simple.
import maya.cmds as mc
def getUniqueObjects(selection):
d = {}
for mesh in selection:
pos = tuple(mc.xform(mesh, query=True, translation=True))
d[pos] = mesh
return d.values()
No comments:
Post a Comment