Closest nth points


I’m trying to create orthogonal dimensions between the center of multiple elements, as you can see in the image bellow. I already found their center points, but how to draw orthogonal lines between all those points?

I already tried to the Geometry.DistanceTo, but I can’t find the solution to get only the nth closest points (for instance, the 4 closest points for every point). I tried List .Sort but the number of points (336) makes the distance between all them (336*336 = 112.896) too hard to deal.

I think that if I find the 4 closest points for each point, I can draw the dimensions between them by using their point X and point Y values. But if there is another easier way to do that, it’s welcome.

Any help will be very appreciated!



Would that help?

But now how do you sort the points from the first list (List.Flatten) after that?

Hi @kevin.carvalho

Maybe this will help.

1 Like

List.SortByKey with the original points as the list and the distances as the keys.

1 Like

Yeah, I’ve done that. But the SortByKey node doesn’t support lists inside lists, and if I Flatten them to Chop it after sorting, it freezes because of the number of points. Clearly, Dynamo has no OOTB node to solve this.

I think this should get you the list of points

1 Like

A review of list levels might be helpful here.

As you can see, the problem isn’t the way I’m managing the list levels. The component can’t work with lists as keys, as I explained.

This one gets me close to it! Thanks! But the problem is that the script only group the points by maximum distance. This is a problem because I can’t find the 4 closest points for every point with this script, and I’m not able to edit python.

The error is a little misleading. Lists cannot represent a single key. The node however can handle sublists of keys for multiple lists. Remove the list levels from list and change keys to @L2.


@kevin.carvalho this should help explain what @Nick_Boyts is talking about.

ClosestFourPointsToPoint.dyn (21.7 KB)

1 Like

Thanks, @mzjensen and @Nick_Boyts. The problem is that I’m from Grasshopper, and there the lists are managed differently. The top-bottom logic from Dynamo from time to time makes me get into trouble. Thank you for showing through the script example, @mzjensen.

Attached, you’ll find my script, which is working perfectly, as you can see in the image below.

I have one last question:

The Dynamo for Civil 3D looks like that has no node for creating DImensions (DIM command). So I have the lines that I want to convert to Dimensions, but I’m not able to do it with any node. Clockwork seems to have that for Revit, but not for Dynamo.

Any help will be appreciated.

cotar grautes v00.DYN (62.2 KB)

There may be a solution for this in the Civil 3D Toolkit, and if not you might have to code it up yourself. Since that is a separate issue from your topic, can you:

  1. Mark the post which gave you the most guidance towards the resolution as a solution so that future visitors can solve the same problem by following your footsteps
  2. Start a new topic for creating dimensions, after checking the Civil 3D Toolkit and the forum for an existing topic.