An example using vectors operations
import clr
import sys
import System
#
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def dim_to_BoundLine(dim):
curvDim = dim.Curve
direction = curvDim.Direction
start = dim.Origin.Subtract(direction.Multiply( dim.Value/2))
end = dim.Origin.Subtract(direction.Multiply(-1 * dim.Value/2 ))
#
return DB.Line.CreateBound(start, end)
def get_distance_beetween(dimA, dimB):
lineA = dim_to_BoundLine(dimA)
lineB = dim_to_BoundLine(dimB)
pta = lineA.GetEndPoint(0)
ptb = lineB.GetEndPoint(0)
normalA = lineA.Direction.CrossProduct(XYZ.BasisZ)
vector_lines = ptb.Subtract(pta)
distance = vector_lines.DotProduct(normalA.Normalize())
return f"{abs(distance) * 304.8:0.1f} mm"
#Preparing input from dynamo to revit
dimA = UnwrapElement(IN[0])
dimB = UnwrapElement(IN[1])
OUT = get_distance_beetween(dimA, dimB)