# Compute Closest Points between two curves

**URL:** <https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171>\
**Category:** Revit\
**Tags:** python\
**Created:** [August 24, 2023, 3:23pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171 "2023-08-24T15:23:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopher.riddell](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@christopher.riddell](https://forum.dynamobim.com/u/christopher.riddell)\
**Post date:** [August 24, 2023, 3:23pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/1 "2023-08-24T15:23:53Z")

</div>

I’m attempting to get the distance between the closest two points, but struggling to figure out the final input (which in C# is show as out resultList) to get it to work.

The code I have is :

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

And the error message I get is :

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/7/5791d7dc5e2d2139e761f3333c188f0135c3dfb9.png)

I can’t seem to get past this. Any thoughts?

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [August 24, 2023, 7:21pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/2 "2023-08-24T19:21:07Z")

</div>

@christopher.riddell ,

thats the concept idea?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/2/a260d6d27d11af223e6ffbf0cbe024de79b31a2d.jpeg)  
KR  
Andreas

---

<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:** [August 24, 2023, 7:43pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/3 "2023-08-24T19:43:22Z")

</div>

Hello, follow [this link](https://forum.dynamobim.com/t/reverse-dimension-location/76793/6) you will have the answers to your questions

> **a try**
>
> ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/0/a0180eb69813700f1f3dac485e221334f08747e0.png)
> 
> ```auto
> import clr
> import sys
> 
> import System
> 
> from System.Collections.Generic import List,IList
> 
> clr.AddReference("RevitNodes")
> import Revit
> 
> clr.ImportExtensions(Revit.GeometryConversion)
> clr.AddReference("RevitServices")
> import RevitServices
> from RevitServices.Persistence import DocumentManager 
> from RevitServices.Transactions import TransactionManager 
> 
> clr.AddReference("RevitAPI")
> 
> import Autodesk 
> from Autodesk.Revit.DB import *
> 
> doc = DocumentManager.Instance.CurrentDBDocument
> 
> #######OK NOW YOU CAN CODE########
> elem1=UnwrapElement(IN[0])
> elem2=UnwrapElement(IN[1])
> 
> a=elem1.Location.Curve
> b=elem2.Location.Curve
> outrefClosest = clr.Reference[IList[ClosestPointsPairBetweenTwoCurves]](List[ClosestPointsPairBetweenTwoCurves]())
> res=ClosestPointsPairBetweenTwoCurves()
> lst=IList[ClosestPointsPairBetweenTwoCurves]
> #c=a.ComputeClosestPoints(b,True,True,True,lst)
> d=a.ComputeClosestPoints(b,True,True,True,outrefClosest)
> closestPt=outrefClosest.Value[0]
> distance=0.3048*closestPt.Distance
> Pt_curv1=closestPt.XYZPointOnFirstCurve.ToPoint()
> OUT =type(lst),type(outrefClosest),closestPt,distance,Pt_curv1
> 
> ```

I tried in CPython with no success.  
cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![christopher.riddell](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@christopher.riddell](https://forum.dynamobim.com/u/christopher.riddell)\
**Post date:** [August 24, 2023, 9:06pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/4 "2023-08-24T21:06:54Z")

</div>

Yeah that was the concept… i ended up pivoting and leveraging those very nodes but in python form so Geomery.ClosestPointTo(Curve1, Pt1) and got closer to my final goal ; however, still stumped as to why the method from the API gave me that error.

---

<div class="post-metadata">

**Author:** ![christopher.riddell](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@christopher.riddell](https://forum.dynamobim.com/u/christopher.riddell)\
**Post date:** [August 24, 2023, 9:07pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/5 "2023-08-24T21:07:57Z")

</div>

thanks for the information , I’ll def check that one out as well.

---

<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:** [August 25, 2023, 8:21am UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/6 "2023-08-25T08:21:00Z")

</div>

Hi @christopher.riddell  
You can use

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/e/3e6291e7bfceec89bb30100cd5684da0a49ace4e.png)  
from BriMohareb\_XXXX pak.

---

<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:** [August 25, 2023, 6:38pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/7 "2023-08-25T18:38:11Z")

</div>

hi, finally found in CPython (with great difficulty)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/4/a48e229f5365dc020e3d88c87aff6ca97eb53a22.png)  
Thanks Mr. Nick and Mr. Jacob

```auto
elem1=UnwrapElement(IN[0])
elem2=UnwrapElement(IN[1])
a=elem1.Location.Curve
b=elem2.Location.Curve

lst=List[ClosestPointsPairBetweenTwoCurves]
c=a.ComputeClosestPoints(b,True,True,True,lst())

dis=0.3048*c[0].Distance
pt1=c[0].XYZPointOnFirstCurve.ToPoint()
pt2=c[0].XYZPointOnSecondCurve.ToPoint()

OUT=c,dis,pt1,pt2

```

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![christopher.riddell](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@christopher.riddell](https://forum.dynamobim.com/u/christopher.riddell)\
**Post date:** [August 25, 2023, 7:33pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/8 "2023-08-25T19:33:32Z")

</div>

wow this is awesome. Thank you so much for diving deep into that one.

I for the life of me could not figure out how to get that method set up and in the short term leaned on calling the dynamo node for closest point but really wanted to do it just like you have shown.

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

Thanks again for the help I really appreciate it!

---

<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:** [August 25, 2023, 8:15pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/9 "2023-08-25T20:15:15Z")

</div>

Thank you, but without Mr. Poupin’s Initial post, (My reaction would have been: number of head scratches before getting there:  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/2/b2b38c134d79cbffeb51671c7a342c334f57a7ea.png)

the magicians are elsewhere (humble as well)

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![sensiblehira](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@sensiblehira](https://forum.dynamobim.com/u/sensiblehira)\
**Post date:** [January 14, 2024, 2:13pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/10 "2024-01-14T14:13:25Z")

</div>

> [@christian.stan](#):
>
> `lst=List[ClosestPointsPairBetweenTwoCurves]`

someone explain this part of code to me so that I can use the knowledge for other methods in the api as well

---

<div class="post-metadata">

**Author:** ![sensiblehira](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@sensiblehira](https://forum.dynamobim.com/u/sensiblehira)\
**Post date:** [January 14, 2024, 2:21pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/11 "2024-01-14T14:21:47Z")

</div>

I am getting error though for this

---

<div class="post-metadata">

**Author:** ![sensiblehira](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@sensiblehira](https://forum.dynamobim.com/u/sensiblehira)\
**Post date:** [January 14, 2024, 2:23pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/12 "2024-01-14T14:23:34Z")

</div>

it says Name List is not defined

---

<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:** [January 15, 2024, 7:43pm UTC](https://forum.dynamobim.com/t/compute-closest-points-between-two-curves/93171/13 "2024-01-15T19:43:59Z")

</div>

Hello, you need an Output list (see api)

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

you must have these 2 lines of code

```auto
import System
from System.Collections.Generic import List,IList

```

to have an output container  
by specifying the type of container.

Sincerely  
christian.stan
