如何通过Revit API获取非Stairs类楼梯的Actual Tread Depth
Hey there! I’ve run into a similar issue before with custom or family-based stairs in Revit, so let’s break down how to get that Actual Tread Depth parameter even when your stairs aren’t part of the Autodesk.Revit.DB.Architecture.Stairs class.
1. First, confirm your stair's actual type
Since the stair doesn’t inherit from the native Stairs class, it’s almost certainly a FamilyInstance—this is common for pre-loaded family stairs, custom stair families, or stairs created by third-party tools. You can verify this with a quick check in code:
// Assume 'selectedElement' is the stair object you've selected if (selectedElement is FamilyInstance stairFamily) { // This confirms it's a family-based stair Debug.WriteLine("Stair is a FamilyInstance"); }
2. Retrieve the Actual Tread Depth parameter
Even though you can’t access it as a direct property like the native Stairs.ActualTreadDepth, you can fetch it using Revit’s parameter lookup methods. Here are two reliable approaches:
Option 1: Use LookupParameter() (by display name)
This works if you know the exact display name shown in the properties panel. Note that this might vary if Revit is set to a different language, so keep that in mind:
Parameter treadDepthParam = selectedElement.LookupParameter("Actual Tread Depth"); if (treadDepthParam != null && treadDepthParam.HasValue) { // Revit uses internal units (feet), convert to your desired unit (e.g., mm) double depthInFeet = treadDepthParam.AsDouble(); double depthInMm = UnitUtils.ConvertFromInternalUnits(depthInFeet, DisplayUnitType.DUT_MILLIMETERS); Debug.WriteLine($"Actual Tread Depth: {depthInMm} mm"); }
Option 2: Use GetParameter() (by GUID, more stable)
For better stability (especially if you’re dealing with localized Revit versions), find the parameter’s unique GUID using the Revit Lookup tool (a must-have for Revit API devs). Once you have the GUID, use it to fetch the parameter:
// Replace with the actual GUID for "Actual Tread Depth" from Revit Lookup Guid treadDepthGuid = new Guid("INSERT_PARAMETER_GUID_HERE"); Parameter treadDepthParam = selectedElement.GetParameter(treadDepthGuid); if (treadDepthParam != null && treadDepthParam.HasValue) { double depthInFeet = treadDepthParam.AsDouble(); double depthInMm = UnitUtils.ConvertFromInternalUnits(depthInFeet, DisplayUnitType.DUT_MILLIMETERS); Debug.WriteLine($"Actual Tread Depth: {depthInMm} mm"); }
3. Why isn't it a Stairs class?
The native Autodesk.Revit.DB.Architecture.Stairs class only applies to stairs created directly using Revit’s built-in stair creation tools. Any stair that’s a loaded family (from the Revit library or custom-made) will be a FamilyInstance, so you have to rely on parameter lookup instead of class properties.
Pro Tip
Grab the Revit Lookup tool if you don’t already have it—it lets you inspect any element’s type, parameters, GUIDs, and more directly in the Revit UI, which is invaluable for troubleshooting API issues like this.
内容的提问来源于stack exchange,提问作者Zephyrus

