Formats a number with units into a string.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 18.0.0.0 (18.2.0.13)
Since:
2014
Syntax
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
CopyC#
void DisplayDensityOfMaterial(Material material)
{
double density = 0;
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;
Units units = material.Document.GetUnits();
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);
}
}
}
CopyVB.NET
Private Sub DisplayDensityOfMaterial(material As Material)
Dim density As Double = 0
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
Dim units As Units = material.Document.GetUnits()
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
See Also