Getting wrong stairs length/width from Python & Revit API

Hi everyone

I have some python code, apparently running ok, to get the horizontal area of two stair runs getting their line boundaries through Revit API. The code seems to be working, but I am getting all lengths multiplied by more or less 3, more or less (default width is 1.00 m and I’m getting 3.28 m).

Does anybody know what could be going on? Thank you all so much in advance

stairs = UnwrapElement(IN[0])

runIds = stairs.GetStairsRuns()
runs = [stairs.Document.GetElement(runId) for runId in runIds]
bounds = [run.GetFootprintBoundary() for run in runs]

len = []	
for bound in bounds:
	for line in bound:
		len.append(line.ApproximateLength)
	

isplanar = [bound.HasPlane() for bound in bounds]
planes = [bound.GetPlane() for bound in bounds]
isopen = [bound.IsOpen() for bound in bounds]

isrect = []
areas = []
width = []
height = []

for plane in planes:
	isrect.append(bounds[planes.index(plane)].IsRectangular(plane))
	if isrect[planes.index(plane)] is True:
		width.append(bounds[planes.index(plane)].GetRectangularWidth(plane))
		height.append(bounds[planes.index(plane)].GetRectangularHeight(plane))
		areas.append(bounds[planes.index(plane)].GetRectangularWidth(plane)*bounds[planes.index(plane)].GetRectangularHeight(plane))
	else:
		areas.append('error')


OUT = runs, bounds, len, isplanar, isopen, isrect, areas, width, height

The units being returned are likely incorrect. 3.28 feet = 1 meter if memory serves.

3 Likes

Yes, results are returned in FEET as Revits internal units. You could look for a conversion node or change units in the Python node.

decimal_feet_length = detail_line.GeometryCurve.Length
metric_length = UnitUtils.Convert(decimal_feet_length, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS)
OUT = metric_length
1 Like

Thanks Jacob. Dividing the lengths by 3.28 certainly solved the issue, which is interesting because the first thing I did was to check the units in the Revit file and they were in metric system.

Thank you Sean. I tried that and I get the following error: “UnitUtils is not defined”. Is there any module or library I’d need to import?

Here is an example using Revit 2022, but the import should be the same.

import clr

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

OUT = UnitUtils.Convert(11.7,UnitTypeId.Feet,UnitTypeId.Millimeters)

Keep in mind too that in R2021 the DisplayUnitType was depreciated, and then in R2022 is it replaced by the SpecTypeId, ForgeTypeId and UnitTypeId classes.

1 Like