Formats a number with units into a string.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2014
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- units
- Type: Autodesk.Revit.DB Units
The units formatting settings, typically obtained from Document.GetUnits() .
- unitType
- Type: Autodesk.Revit.DB UnitType
The unit type of the value to format.
- value
- Type: System Double
The value to format, in Revit's internal units.
- maxAccuracy
- Type: System Boolean
True if the value should be rounded to an increased accuracy level appropriate for editing or understanding the precise value stored in the model. False if the accuracy specified by the FormatOptions should be used, appropriate for printed drawings.
- forEditing
- Type: System Boolean
True if the formatting should be modified as necessary so that the formatted string can be successfully parsed, for example by suppressing digit grouping. False if unmodified settings should be used, suitable for display only.
Return Value
The formatted string.Examples

void DisplayDensityOfMaterial(Material material)
{
double density = 0;
// get structural asset of material in order to get the density
ElementId strucAssetId = material.StructuralAssetId;
if (strucAssetId != ElementId.InvalidElementId)
{
PropertySetElement pse = material.Document.GetElement(strucAssetId) as PropertySetElement;
if (pse != null)
{
StructuralAsset asset = pse.GetStructuralAsset();
density = asset.Density;
// convert the density value to a user readable string that includes the units
Units units = material.Document.GetUnits();
// false for maxAccuracy means accuracy specified by the FormatOptions should be used
// false for forEditing since this will be for display only and no formatting modifications are necessary
string strDensity = UnitFormatUtils.Format(units, UnitType.UT_UnitWeight, density, false, false);
string msg = string.Format("Raw Value: {0}\r\nFormatted Value: {1}", density, strDensity);
TaskDialog.Show("Material Density", msg);
}
}
}

Private Sub DisplayDensityOfMaterial(material As Material)
Dim density As Double = 0
' get structural asset of material in order to get the density
Dim strucAssetId As ElementId = material.StructuralAssetId
If strucAssetId <> ElementId.InvalidElementId Then
Dim pse As PropertySetElement = TryCast(material.Document.GetElement(strucAssetId), PropertySetElement)
If pse IsNot Nothing Then
Dim asset As StructuralAsset = pse.GetStructuralAsset()
density = asset.Density
' convert the density value to a user readable string that includes the units
Dim units As Units = material.Document.GetUnits()
' false for maxAccuracy means accuracy specified by the FormatOptions should be used
' false for forEditing since this will be for display only and no formatting modifications are necessary
Dim strDensity As String = UnitFormatUtils.Format(units, UnitType.UT_UnitWeight, density, False, False)
Dim msg As String = String.Format("Raw Value: {0}" & vbCr & vbLf & "Formatted Value: {1}", density, strDensity)
TaskDialog.Show("Material Density", msg)
End If
End If
End Sub
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions ArgumentException | unitType is an invalid unit type. See UnitUtils.IsValidUnitType() and UnitUtils.GetValidUnitTypes(). -or- The given value for value is not finite |
Autodesk.Revit.Exceptions ArgumentNullException | A non-optional argument was NULL |
Autodesk.Revit.Exceptions ArgumentOutOfRangeException | A value passed for an enumeration argument is not a member of that enumeration |