# Join Lines with extend line

**URL:** <https://forum.dynamobim.com/t/join-lines-with-extend-line/89449>\
**Category:** Revit\
**Tags:** revit, python, dynamo, civil3d\
**Created:** [May 10, 2023, 5:12pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449 "2023-05-10T17:12:48Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [May 10, 2023, 5:12pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/1 "2023-05-10T17:12:48Z")

</div>

Join Points with extend line  
 ![33333](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/9/095eef220c8181bf3699b3cf1af724f15e7acc76.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 10, 2023, 6:47pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/2 "2023-05-10T18:47:16Z")

</div>

Are you looking to merge the lines into one line, or connect the two as a polycurve to account for lines which are not aligned?

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [May 10, 2023, 8:00pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/3 "2023-05-10T20:00:14Z")

</div>

I want to add lines between lines (The problem that connect to closest point but I want to add angle… So that it is along the lines or closer to the extension, but does not connect perpendicular to the line  
 ![2222](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/e/ce8d5731fda6621f76214f56719bc416c2d6ec2b.png)

---

<div class="post-metadata">

**Author:** ![ruben.romero](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ruben.romero/32/115842_2.png) [@ruben.romero](https://forum.dynamobim.com/u/ruben.romero)\
**Post date:** [May 12, 2023, 8:37pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/4 "2023-05-12T20:37:19Z")

</div>

> [@ENGRMA1234](#):
>
> I want to add lines between lines

Get the points of the lines, sort them clockwise by their point coordinates x and y and create a polycurve then explode the geometry and sort curves by length? Then get the first and the second of the list which are longest as the result

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [May 13, 2023, 12:03am UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/6 "2023-05-13T00:03:21Z")

</div>

How can I use clockwise?  
And is there a way to extend lines to meet the other line?

---

<div class="post-metadata">

**Author:** ![ruben.romero](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ruben.romero/32/115842_2.png) [@ruben.romero](https://forum.dynamobim.com/u/ruben.romero)\
**Post date:** [May 13, 2023, 12:31am UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/7 "2023-05-13T00:31:01Z")

</div>

> [@ENGRMA1234](#):
>
> extend lines

You didn’t ask to extend lines you are asking to add lines to fill the gap. I don’t know if is possible to extend lines, what are the lines in Revit?

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [May 13, 2023, 7:03am UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/8 "2023-05-13T07:03:58Z")

</div>

Hello, there must certainly be faster but it should work

 ![13 Mai Forum anglais rep_2023-05-13_09-03-21](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/c/dc20fb7bc5f3d5c97e811ab0d19e887049c9b474.png)

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [May 13, 2023, 12:59pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/9 "2023-05-13T12:59:39Z")

</div>

Lines from cad

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [May 13, 2023, 1:04pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/10 "2023-05-13T13:04:54Z")

</div>

If I have more than 4 points  
I want to be a general .  
 ![11111111](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/2/12e4737a2d2b7817e552485df9ed4478bdf6b2fc.png)

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [May 13, 2023, 1:49pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/11 "2023-05-13T13:49:01Z")

</div>

Hello, you will have to adapt in this case  
1st trick 2 points 2nd trick 4 points

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 13, 2023, 1:51pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/12 "2023-05-13T13:51:52Z")

</div>

We need a dataset to help; post the DWG witht he condition(s) your’e working with.

Mostly they seem to work with a PolycCurve.ByJoinedCurves, and a PolyCurve.CloseWithLine node.

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [May 13, 2023, 2:22pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/13 "2023-05-13T14:22:51Z")

</div>

[Test1.dwg](https://forum.dynamobim.com/uploads/short-url/4DB9Lur10oxAXwdSTwPRvQ9qwke.dwg) (1.6 MB)

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [May 13, 2023, 2:33pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/14 "2023-05-13T14:33:02Z")

</div>

> [@jacob.small](#):
>
> PolyCurve.CloseWithLine

PolyCurve.CloseWithLine is good but when this case  
 ![44444444](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/5/55081694261a4e3b886b03953d0f7db1903109a9.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 14, 2023, 1:11pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/15 "2023-05-14T13:11:31Z")

</div>

It’s likely there is a better way to solve the larger problem this is a part of, but this Python will take a PolyCurve and join it to an adjacent PolyCurve by drawing the line from the end point of the first Polycurve to the closest point at parameter 0 or 1 of the second PolyCurve. It also has an optional boolean input to close the entire curve as needed, and will work with a series of PolyCurveas well.

Careful selection of the curves to make PolyCurve, or use of the GroupCurves node (from [Archi-Lab](https://forum.dynamobim.com/t/revit-2022-dynamo-2-10-package-not-showing-up-and-icons-missing/62933/7?)) or your own method thereof should make this workable.

```auto
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import PolyCurve, Geometry, Curve, Line

inCrvs = IN[0] #the curves from the Dynamo environment
closePoly = IN[1] #boolean indicated if the polycurve should be closed
joinedCurve = PolyCurve.ByJoinedCurves([inCrvs.pop()]) #take one curve out of the inCrvs list and convert it to a PolyCurve

while inCrvs: #while there are items in the inCrvs list
    endPnt = Curve.PointAtParameter(joinedCurve,1) #get the end point of the 
    dists = [Geometry.DistanceTo(endPnt,i) for i in inCrvs] #get the distance from the end of the initial curve to each curve still in the inCrvs list
    next = [x for y,x in sorted(zip(dists,inCrvs))][0] #gest the next curve from the in crvs list based on the shorted distance to the end point
    nextPnts = [Curve.PointAtParameter(next,i) for i in [0,1] ] #get the start and end point from the next curve
    pntDists = [Geometry.DistanceTo(endPnt,i) for i in nextPnts] #get the distance from the end point of the init curve to the start and end point of the next cruve 
    nextPnt = [x for y,x in sorted(zip(pntDists,nextPnts))][0] #get the cloest of the next curves end points to the init curves endpoint
    newLine = Line.ByBestFitThroughPoints([endPnt,nextPnt]) #build a line from the closest end point of teh next curve to teh end point of the init curve
    joinedCurve = PolyCurve.ByJoinedCurves([joinedCurve,newLine,next]) #build a new polycurve from the init curve, next curve, and new line
    inCrvs.remove(next) #remove the next curve from the list of inCrvs

if closePoly: joinedCurve = PolyCurve.CloseWithLine(joinedCurve)

OUT = joinedCurve #returns the joined polycuve to the Dynamo environment

```

---

<div class="post-metadata">

**Author:** ![RMohareb](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rmohareb/32/120534_2.png) [@RMohareb](https://forum.dynamobim.com/u/RMohareb)\
**Post date:** [May 14, 2023, 1:59pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/16 "2023-05-14T13:59:10Z")

</div>

You can use this node from “BriMohareb\_2023”

 ![Screenshot_20230514_152628_Samsung Internet](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/1/51d1cda176d950f1a96f5644be4b71010b97ddd6.jpeg)

> [@Join the cad line in dynamo](https://forum.dynamobim.com/t/join-the-cad-line-in-dynamo/89783/3):
>
> @ali_arch Use “BriMohareb\_20XX” pak. from Dynamo Revit 2023 or 2024 [Join\_TwoLine.dyn](https://forum.dynamobim.com/uploads/short-url/8kliQIJf9Qj6nWcToivyGCob2jh.dyn) (18.8 KB)

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [June 2, 2023, 9:21am UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/17 "2023-06-02T09:21:12Z")

</div>

@jacob.small I tried to apply the code repeatedly, but it always gets an error, and I don’t know the cause of the problem

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [June 2, 2023, 10:55am UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/18 "2023-06-02T10:55:41Z")

</div>

I can’t reproduce - post your DYN where you implemented it, along with a dataset to do so (ie: a Revit file with the necessary objects in it to just run the Dynamo graph).

---

<div class="post-metadata">

**Author:** ![ENGRMA1234](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ENGRMA1234](https://forum.dynamobim.com/u/ENGRMA1234)\
**Post date:** [June 2, 2023, 2:24pm UTC](https://forum.dynamobim.com/t/join-lines-with-extend-line/89449/19 "2023-06-02T14:24:00Z")

</div>

[Column.dwg](https://forum.dynamobim.com/uploads/short-url/yV5xZJNY00T0x7Jz0wR4aNmAgGW.dwg) (1.5 MB)
