Closest point from long list to a point in a shorter list

Hi guys I am getting weird results when trying to find the closest point in the shorter list from the longer list. I shouldnt be getting the duplicate results like this. I tried multiple nodes with dubious results. See below. Does anyone know why this isnt working? Thanks in advance!

Hmm, without seeing the internal of the custom node (perhaps there is an issue with reading the correct index within) I can only offer another option.
Give this a try :wink:

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Inputs
short_list = IN[0]
long_list = IN[1]

# Output list
result = []

# Loop check for each point in the short list
for s in short_list:	
	# List for distances
	dist = []
	for l in long_list:
		# Distance to point s
		d = Geometry.DistanceTo(s,l)
		dist.append(d)
	# Lowest distance in list		
	min_d = min(dist)
	# Index of lowest distance in list
	min_ind = dist.index(min_d)
	# Get the closest point from the long_list
	closest_p = long_list[min_ind]
	# Add the point to the results, as it is the closest to the point from the short list
	result.append(closest_p)

# Output the results
OUT = result
3 Likes

I’m not sure, but I think that happen when you did not set the ‘Lacing’ setting correctly.


That is an example of what I mean. Sometimes ‘Lacing’ become very confusing, I sometimes use python too if can’t figure out how the setting should be