# Group Lines

**URL:** <https://forum.dynamobim.com/t/group-lines/113620>\
**Category:** Packages\
**Tags:** dynamo\
**Created:** [January 9, 2026, 12:28pm UTC](https://forum.dynamobim.com/t/group-lines/113620 "2026-01-09T12:28:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hayet.sassi2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hayet.sassi2/32/199553_2.png) [@hayet.sassi2](https://forum.dynamobim.com/u/hayet.sassi2)\
**Post date:** [January 9, 2026, 12:28pm UTC](https://forum.dynamobim.com/t/group-lines/113620/1 "2026-01-09T12:28:35Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/3/13ee103bd961d1d5a0ceaba4eb67df1b28c39702.jpeg)  
Hello everyone, I’m trying to group parallel lines together to create walls. My problem is that, as shown on the screen, I used Springs.Geometry.GroupByDistance, and even though I set a margin, some lines are still being placed in the same group even though they don’t belong to the same wall. Any help would be appreciated. Thank you.

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [January 11, 2026, 11:16am UTC](https://forum.dynamobim.com/t/group-lines/113620/2 "2026-01-11T11:16:08Z")

</div>

Hi @hayet.sassi2 ,

I am assuming that you now first made groups of parallel wall lines, from 0-180° (or maybe in steps of 5°) and then group using a certain tolerance.

Instead I’d suggest the following order:

1. Instead of grouping by a given distance, extend/ buffer the current wall lines in the direction of the wall on both sides, using the same distance that you use now.
2. Then use the group by distance node, using a very tiny distance (0.01) to only find overlaps, to find those that actually overlap.

---

<div class="post-metadata">

**Author:** ![hayet.sassi2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hayet.sassi2/32/199553_2.png) [@hayet.sassi2](https://forum.dynamobim.com/u/hayet.sassi2)\
**Post date:** [January 11, 2026, 11:59am UTC](https://forum.dynamobim.com/t/group-lines/113620/3 "2026-01-11T11:59:29Z")

</div>

Hello, thank you for your response. Could you please elaborate on the first instruction? I’m not sure I understand

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [January 12, 2026, 12:08pm UTC](https://forum.dynamobim.com/t/group-lines/113620/4 "2026-01-12T12:08:57Z")

</div>

There are nodes like Curve.Extend, Curve.ExtendEnd and Curve.ExtendStart which you can use to extend the curves in the direction of their vector.

Maybe this illustration helps, the red are you lines now, and the green ones are the extended ones. Then using those green, extended ones, you can check which intersect. Which in my example, only the top 2 do, and the bottom 2 don’t.

 ![Naamloos](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/f/6faa8f10f8e98d4c7ab1078d99b476d756f09508.png)

(I might have misunderstood your current input though)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [January 12, 2026, 1:42pm UTC](https://forum.dynamobim.com/t/group-lines/113620/5 "2026-01-12T13:42:32Z")

</div>

Hi,

You can try grouping the parallel lines by distance from the midpoint of the lines.

Here’s the principle.

`midPointonCurveA.DistanceTo(CurveB) < minDistance`

---

<div class="post-metadata">

**Author:** ![Durmus\_Cesur](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/durmus_cesur/32/62638_2.png) [@Durmus\_Cesur](https://forum.dynamobim.com/u/Durmus_Cesur)\
**Post date:** [January 12, 2026, 1:43pm UTC](https://forum.dynamobim.com/t/group-lines/113620/6 "2026-01-12T13:43:55Z")

</div>

Hi

There are actually a few ways to do this, I use **Shapely** for this type of geometric analysis.

Here’s a different solution:  
With **Shapely.TouchesByDistance** , we can analyse the relationships between geometries using “Margin”.

 ![TouchesbyDistance](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/3/03e6516d910ab25e701ed1db0e76206abc0e6a83.png)

 ![TouchesbyDistance-0](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/3/730b9184ba8cb72c519a70324c0df443119252bb.png)

**Shapely.Touches** : It checks whether there is any boundary contact between two geometries. In this way, we can see which geometry is in contact with the geometry I am querying

 ![TouchesbyDistanceavecTouches-0](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/c/3cf21d1874c8d4369ad65b2fe07b3096ec2c4adc.png)

 ![TouchesbyDistanceavecTouches](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/2/024a207bd9d54a48f5bd7b274b9ca4cfc5b5d772.png)

---

<div class="post-metadata">

**Author:** ![hayet.sassi2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hayet.sassi2/32/199553_2.png) [@hayet.sassi2](https://forum.dynamobim.com/u/hayet.sassi2)\
**Post date:** [January 12, 2026, 7:11pm UTC](https://forum.dynamobim.com/t/group-lines/113620/7 "2026-01-12T19:11:10Z")

</div>

Hello, and thank you all for your responses. I realize now that I wasn’t very clear in explaining my problem.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/e/def950f9b3bfa779242e86e383b07c5b3fb31d35.png)

I’ve added a screenshot to help illustrate it. I’m working with a DWG file and trying to create walls using parallel lines. However, my drawing contains lines with various thicknesses. To manage this, I set the margin for parallel lines to 0.4.

The issue is that, as shown in the screenshot, Dynamo groups four lines together because the distance between them is less than 0.4.

---

<div class="post-metadata">

**Author:** ![Durmus\_Cesur](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/durmus_cesur/32/62638_2.png) [@Durmus\_Cesur](https://forum.dynamobim.com/u/Durmus_Cesur)\
**Post date:** [January 13, 2026, 12:25am UTC](https://forum.dynamobim.com/t/group-lines/113620/8 "2026-01-13T00:25:21Z")

</div>

Hi,

Hmm… K-means might be a good solution.

Using K-means, you can perform analysis directly based on the spatial (space) positions of the data without relying on a fixed value for wall thickness. This makes it possible to group similar geometries very quickly.

 ![Kmeans-GroupLines](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/8/1851c9d275b1d001527a7e8f0e4912048081c11b.png)

 ![Kmeans-GroupLines-0](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/c/0ce9641410de123bea57747e73c67b48b40e0e60.png)

> # Copyright(c) 2023, Durmus Bayryam  
> import sys  
> import clr
> 
> import numpy **as** np  
> from sklearn.cluster import KMeans
> 
> data = IN[0]  
> n\_clusters = IN[1]
> 
> #Processing
> 
> X\_train = np.array(data)
> 
> #Model Fit
> 
> model = KMeans(n\_clusters=n\_clusters, random\_state=42)  
> model.fit(X\_train)
> 
> #Predict
> 
> labels = model.predict(X\_train)
> 
> OUT = labels
