I have a big list of point objects, with each point object having a unique ‘name’.
I am using CullDuplicatePoints to remove the points that are too close together. However, it seems to me that resulting list is just a list of Point3d coordinates, rather than any of the original GUIDs from the original list. At the moment I am using this list to recreate a new list of point objects, but of course these don’t have the names.
What I am looking for is a way to either:
a. use the resulting culled list to delete from the original list of named point objects.
or b: a way to reallocate the names from the original points to the new ones.
There is already a class with better behavior RTree, but it is a bit more difficult to understand. You could edit this method or write an algorithm based on the RTree class?
import rhinoscriptsyntax as rs
import scriptcontext
import copy
tol = scriptcontext.doc.ModelAbsoluteTolerance
def removeDuplicates(points):
# Create a dictionary to keep track of the Id
pointDict = {}
ptList = []
for pt in points:
pt3d = rs.coerce3dpoint(pt)
pointDict[pt3d] = pt
ptList.append(pt3d)
#sortList
ptList.sort()
ptLast = ptList[-1]
for i in range(len(ptList)-2,-1,-1):
if (abs(ptList[i][0]-ptLast[0]) < tol) and (abs(ptList[i][1]-ptLast[1])) < tol and (abs(ptList[i][2]-ptLast[2]) < tol):
del ptList[i]
else:
ptLast = ptList[i]
#find the the ids with the new list
outputList = []
for pt in ptList:
ptId = pointDict[pt]
outputList.append(ptId)
return outputList
a = removeDuplicates(points)
I hope this is what you are looking for I have also attached a GH version.