Prune points but keep list order

Hello everyone,

I’m trying to prune duplicate points (same x,y but diff z) and keep the point with the lower z-value.
For example, I want to make this table:

And end up with this:

Grouping by their X values and sub grouped by their Y values, then subgroups are sorted by their Z values doesnt work entirely work because it won’t keep list order. ie this way Points above each other - #2 by Vikram_Subbaiah
Ended up with this:

However, this way works exactly how I wanted - Create Toposurface from Floor - #5 by Nick_Boyts
But as predicted by Nick_Boyts, the cross lacing takes too long for large lists.

Is there another OOTB way to get what I want for big lists? Is there a python script around that find the duplicates?

  1. Pull the point’s X and Y values, and merge them into a string. (p.X+””+p.Y;)

  2. Group the points by that string using a List.GroupByKey.

  3. List.MinimumItemByKey with correct lacing and list level input, using a Point.Z node as the projector will pull the lowest Z from each group.

No cross product lacing involved - the grouping will likely be the slowest action. Fortunately you could quickly limit that to quadrants of your project by only selecting points in one area at a time.

1 Like

Keeping track of the corresponding indices as you group, sort and filter the points would allow you to rearrange the points

prune.dyn (28.0 KB)


an alternative with Python

import sys
import clr
from Autodesk.DesignScript.Geometry import *

def XYHasAlready(pt):
	global pruneLst
	for idx, i in enumerate(pruneLst):
		if abs(i.X - pt.X) < 0.01 and abs(i.Y - pt.Y) < 0.01:
			if pt.Z < i.Z:
				pruneLst[idx] = pt
			return True
	return False
inputPts = IN[0]
pruneLst = []

for pt in inputPts:
	if not XYHasAlready(pt):
OUT = pruneLst

Thanks everyone. I tried all three with success.