Geometry is not scaled after transformation from Revit API to Dynamo geometry

Hi everyone, @Mike.Buttery

Something is wrong in my code, as shown in the image below. The generated arcs are not correctly located (they should be near the outer face of the wall) after transformation from API to Dynamo geometry. This issue is likely due to the non-conversion of angles from radians to degrees, while their lengths and angles are correctly displayed in the output (in meters and degrees).

arcs dynamo
import clr
from math import pi

clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
from Revit.GeometryConversion import *
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

# Helper functions
metres = lambda iu: UnitUtils.ConvertFromInternalUnits(iu, UnitTypeId.Meters)
degrees = lambda rad: UnitUtils.Convert(rad, UnitTypeId.Radians, UnitTypeId.Degrees)

# Inputs
pipe = UnwrapElement(IN[0])
rebar = UnwrapElement(IN[1])

# Get geometry (Largest circle at lowest point)
geom = pipe.get_Geometry(Options())
solids = list(geom.GetTransformed(Transform.Identity))[1]
curves = [e.AsCurve() for e in solids.Edges]
arcs = [c for c in curves if "Arc" in c.ToString()]
max_r_arc = max(arcs, key=lambda c: c.get_Radius()).get_Radius()
min_z_arc = min(
    [arc for arc in arcs if arc.get_Radius() == max_r_arc],
    key=lambda c: c.get_Center().Z,
)

# Parameters
l = 12
cover = 0.05
d = metres(rebar.BarModelDiameter)
r = metres(min_z_arc.get_Radius()) - cover
c = min_z_arc.get_Center()
c = XYZ(c.X, c.Y, c.Z + cover)

# Calculations
number_full_bars = int((2 * pi * r) // (l - 50 * d))
remainder_bar = round((2 * pi * r) - (l - 50 * d) * number_full_bars + 50 * d, 2)
bars = [12] * number_full_bars + [remainder_bar]
start_angles = [(l - 50 * d) / r * n for n in range(number_full_bars + 1)]
end_angles = map(sum, zip([bar / r for bar in bars], start_angles))

# creating arcs around 360 degrees.
out_Arc = []
for i,j in zip(start_angles, end_angles):
    out_arc = Arc.Create(c, r, i, j, XYZ(1, 0, 0), XYZ(0, 1, 0))
    out_Arc.append(out_arc)
    
OUT = [i.Length for i in out_Arc], [i.ToProtoType() for i in out_Arc]

Be kind to check below my dyn and Rvt files

arcs_example.dyn (7.5 KB)

Shaft_example.rvt (7.5 MB)

Any help would be apreciated.

Thanks.

in Revit API internal unit for length is decimal feet

Remove the conversion to meter OR re-convert to decimal feet in Arc.Create method

note : I didn’t check, but the angles must be in radians

5 Likes

@c.poupin

Yes, they are in radians

So the output should be in feet, allowing it to be displayed in meters or other chosen units in the UI?

Your correction solved my issue.

Thanks.

Revit API Unit → Decimal Feet
Dynamo Unit → same as your Project

1 Like