UnitFormatUtils.Format(Units, UnitType, Double, Boolean, Boolean)
Description:
Formats a number with units into a string.
Formats a number with units into a string.
Overloads (6):
Format(Units,UnitType,Double,Boolean,Boolean)
-
unitsThe units formatting settings, typically obtained from Document.GetUnits().
-
unitTypeThe unit type of the value to format.
-
DoublevalueThe value to format, in Revit's internal units.
-
BooleanmaxAccuracyTrue 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.
-
BooleanforEditingTrue 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.
The formatted string.
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);
}
}
}
-
unitType is an invalid unit type. See UnitUtils.IsValidUnitType() and UnitUtils.GetValidUnitTypes(). -or- The given value for value is not finite
-
A non-optional argument was NULL
-
A value passed for an enumeration argument is not a member of that enumeration
👍 0
8
Linked Revit API pages
SpecTypeId.Slope
SpecTypeId.PipingSlope
FabricationPart.Slope
ParameterTypeId.FabricationSlopeParam
UnitFormatUtils.Format
Document.GetUnits
Element.GetParameter
BuiltInParameter
No comments yet. Start the discussion.
Loading…