Hi.

i am trying to implement the Dynamo node “DistanceTo” in some Python nodes, but i am stuck.

I tried the DistanceTo method for both a line and a vector, but i think it is only working for points.

Anyone any idea?

Thanks

Hi.

i am trying to implement the Dynamo node “DistanceTo” in some Python nodes, but i am stuck.

I tried the DistanceTo method for both a line and a vector, but i think it is only working for points.

Anyone any idea?

Thanks

Okay i have figured it out myself with simple geometry formulas:

Here is the code if anyone ever needs it[quote=“laurin.ernstMA6Q3, post:1, topic:58567, full:true”]

But maybe somebody knows a quicker way?

Oh man, yes! First of all you only need to import Revit stuff and do the unwrapping parts if you’re dealing with the Revit API, which in your case you are not.

Since the Dynamo geometry library is “preloaded” with the builtin python template already, all you need to do is this:

```
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
# Place your code below this line
pnt = IN[0]
line = IN[1]
result = pnt.DistanceTo(line)
# Assign your output to the OUT variable.
OUT = result
```

1 Like

For months I’ve been using rotating the geometry so the line is parallel to the XY axis and then using point.project and either the x-axis or y-axis vector to find the intersection point THEN measuring distance between the intersect point and the original!

It never occurred to me I could do this. I feel sooo stupid now