# Group closest parallel lines which are equal in length

**URL:** <https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577>\
**Category:** Packages\
**Tags:** revit, python, dynamo\
**Created:** [March 30, 2018, 6:57am UTC](https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577 "2018-03-30T06:57:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrathnakar](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mrathnakar/32/83799_2.png) [@mrathnakar](https://forum.dynamobim.com/u/mrathnakar)\
**Post date:** [March 30, 2018, 6:57am UTC](https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577/1 "2018-03-30T06:57:16Z")

</div>

Hello dynamobim,  
I want to filter or group the parallel lines which are closer and equal in length. i’m unable to find the custom nodes to group them.

i need some help.

Thank you in advance.

Regards,  
Rathnakar.

---

<div class="post-metadata">

**Author:** ![Nico\_Stegeman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nico_stegeman/32/19204_2.png) [@Nico\_Stegeman](https://forum.dynamobim.com/u/Nico_Stegeman)\
**Post date:** [March 30, 2018, 7:14am UTC](https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577/2 "2018-03-30T07:14:55Z")

</div>

Please show us what you already have

---

<div class="post-metadata">

**Author:** ![mrathnakar](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mrathnakar/32/83799_2.png) [@mrathnakar](https://forum.dynamobim.com/u/mrathnakar)\
**Post date:** [April 10, 2018, 10:09am UTC](https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577/3 "2018-04-10T10:09:33Z")

</div>

this is what i have done…  
i got the parallel lines with equal length.  
But,some lines are grouped with lines which are far away & which are equal in length.  
i’m unable to group the nearest and equal length.  
attached the image with some lines so that u can get what i’m trying to say.  
.

 ![lines](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/c/fc23bdad9883e141a65e3c3c4af53160bd840efc.JPG)

this is way i filtered them.

 ![script](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/8/e8b75743a2d38e12e2d7b61f77fd5b2803722a5a.JPG)

Thank you.

Regards.

---

<div class="post-metadata">

**Author:** ![salvatoredragotta](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/salvatoredragotta/32/10078_2.png) [@salvatoredragotta](https://forum.dynamobim.com/u/salvatoredragotta)\
**Post date:** [April 13, 2018, 4:35am UTC](https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577/4 "2018-04-13T04:35:43Z")

</div>

@mrathnakar Please post your .dyn and .rvt

---

<div class="post-metadata">

**Author:** ![viktor\_kuzev](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/viktor_kuzev/32/48254_2.png) [@viktor\_kuzev](https://forum.dynamobim.com/u/viktor_kuzev)\
**Post date:** [April 13, 2018, 7:47am UTC](https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577/5 "2018-04-13T07:47:57Z")

</div>

I can image a solution with nodes like this:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/1/c128809831e3e69a71bd2b3b02839466fcf91c4c.png)

Checking if they are both parallel and closer than a given margin.  
Because we check each curve with each other we get duplicate groups and we need to use List.UniqueItems.  
This could be avoided using a Python script for example implementing a better checking algorithm

---

<div class="post-metadata">

**Author:** ![viktor\_kuzev](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/viktor_kuzev/32/48254_2.png) [@viktor\_kuzev](https://forum.dynamobim.com/u/viktor_kuzev)\
**Post date:** [April 13, 2018, 8:00am UTC](https://forum.dynamobim.com/t/group-closest-parallel-lines-which-are-equal-in-length/20577/6 "2018-04-13T08:00:49Z")

</div>

An optimized python script to do this would look like this:  
import clr  
clr.AddReference(‘ProtoGeometry’)  
from Autodesk.DesignScript.Geometry import Geometry

```
pts = IN[0]
margin = IN[1]
dist1 = Geometry.DistanceTo

Groups, Queue = [], []
while pts:
	group = []
	Queue.append(pts.pop() )
	while Queue:
		p1 = Queue.pop()
		group.append(p1)
		for i in xrange(len(pts)-1,-1,-1):
			if dist1(p1, pts[i]) <= margin and p1.Direction.IsParallel(pts[i].Direction):
				Queue.append(pts.pop(i) )
	Groups.append(group)

OUT = Groups

```

Kudos to @Dimitar_Venkov since this is a slightly modified version of the Python code in Springs.GroupByDistance node
