SortPointsByDistance IronPython


#1

Hi

It seems that the Rhinoscript method SortPointsByDistance is not available in python. Could you please add it to the in-built python scripting functions?

Many Thanks
M


#2

In the meantime, I use something like the following:

import rhinoscriptsyntax as rs
import Rhino

def SortPointListByDistance(refPt,ptList,revSort):
    distList = [(pt.DistanceTo(refPt), pt, i) for i, pt in enumerate(ptList)]
    distList.sort()
    if revSort: distList.reverse()
    return zip(*distList)

refPtID=rs.GetObject("Select reference point",1)
ptIDs=rs.GetObjects("Select points to compare",1)

rPt=rs.coerce3dpoint(refPtID)
pts=rs.coerce3dpointlist(ptIDs)

distances, sortedPts, indices = SortPointListByDistance(rPt,pts,False)

–Mitch


#3

Thanks Mitch, that’s great! Still it would be great to see this in one of the next SRs.

Best M