Tutorial 2: Parameters Deep Dive
Learn to read element parameters, understand storage types, and handle Revit's internal units.
Finished Script: 03_Tutorials/RevitAPI_Fundamentals/02_ParametersDeepDive.cs
🎯 What You'll Learn
- Accessing Built-in Parameters
- The four Parameter Storage Types
- Converting from internal units to display units
Understanding Parameters
Every Revit element has parameters - properties like Height, Width, Comments, etc. There are two ways to access them:
Built-in Parameters
Pre-defined by Revit, accessed via BuiltInParameter enum:
var param = element.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
Named Parameters
Custom or shared parameters, accessed by name:
var param = element.LookupParameter("My Custom Parameter");
Step 1: Check if Parameter Exists
Always check for null:
var param = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
if (param == null)
{
Println("Parameter not found on this element");
return;
}
Step 2: Read Based on Storage Type
Parameters store values in one of four types:
| StorageType | C# Type | Read Method |
|---|---|---|
String | string | param.AsString() |
Integer | int | param.AsInteger() |
Double | double | param.AsDouble() |
ElementId | ElementId | param.AsElementId() |
string value = param.StorageType switch
{
StorageType.String => param.AsString() ?? "(empty)",
StorageType.Double => param.AsDouble().ToString("F2"),
StorageType.Integer => param.AsInteger().ToString(),
StorageType.ElementId => param.AsElementId().ToString(),
_ => "Unknown type"
};
Step 3: Handle Units
Critical: Revit stores all lengths in feet internally!
double heightInFeet = param.AsDouble();
// Convert to meters
double heightInMeters = UnitUtils.ConvertFromInternalUnits(
heightInFeet,
UnitTypeId.Meters
);
Println($"Height: {heightInMeters:F2} m");
Common unit conversions:
UnitTypeId.Meters- Length in metersUnitTypeId.Millimeters- Length in millimetersUnitTypeId.SquareMeters- Area in m²UnitTypeId.CubicMeters- Volume in m³
Step 4: Common Built-in Parameters
// Wall parameters
BuiltInParameter.WALL_USER_HEIGHT_PARAM // Unconnected Height
BuiltInParameter.CURVE_ELEM_LENGTH // Length
// Room parameters
BuiltInParameter.ROOM_NAME
BuiltInParameter.ROOM_NUMBER
BuiltInParameter.ROOM_AREA
// Universal parameters
BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS
BuiltInParameter.ALL_MODEL_MARK
💡 Try This
- Read and display the Area of all Rooms
- Create a table showing Door widths and heights
- Find all elements with empty Comments parameters