Convert Method


Converts a value from one display unit to another, such as square feet to square meters.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2014

Syntax

C#
public static double Convert(
	double value,
	DisplayUnitType currentDisplayUnit,
	DisplayUnitType desiredDisplayUnit
)
Visual Basic
Public Shared Function Convert ( _
	value As Double, _
	currentDisplayUnit As DisplayUnitType, _
	desiredDisplayUnit As DisplayUnitType _
) As Double
Visual C++
public:
static double Convert(
	double value, 
	DisplayUnitType currentDisplayUnit, 
	DisplayUnitType desiredDisplayUnit
)

Parameters

value
Type: System Double
The value to convert.
currentDisplayUnit
Type: Autodesk.Revit.DB DisplayUnitType
The current display unit.
desiredDisplayUnit
Type: Autodesk.Revit.DB DisplayUnitType
The desired display unit.

Return Value

The converted value.

Examples

Copy C#
void SetTopOffset(Wall wall, double dOffsetInches)
{
    // convert user-defined offset value to feet from inches prior to setting
    double dOffsetFeet = UnitUtils.Convert(dOffsetInches, 
                                            DisplayUnitType.DUT_DECIMAL_INCHES, 
                                            DisplayUnitType.DUT_DECIMAL_FEET);

    Parameter paramTopOffset = wall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET);
    paramTopOffset.Set(dOffsetFeet);
}
Copy VB.NET
Private Sub SetTopOffset(wall As Wall, dOffsetInches As Double)
    ' convert user-defined offset value to feet from inches prior to setting
    Dim dOffsetFeet As Double = UnitUtils.Convert(dOffsetInches, DisplayUnitType.DUT_DECIMAL_INCHES, DisplayUnitType.DUT_DECIMAL_FEET)

    Dim paramTopOffset As Parameter = wall.Parameter(BuiltInParameter.WALL_TOP_OFFSET)
    paramTopOffset.[Set](dOffsetFeet)
End Sub

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException The given value for value is not finite -or- currentDisplayUnit is an invalid display unit. See UnitUtils.IsValidDisplayUnit(DisplayUnitType) and UnitUtils.GetValidDisplayUnits(). -or- desiredDisplayUnit is an invalid display unit. See UnitUtils.IsValidDisplayUnit(DisplayUnitType) and UnitUtils.GetValidDisplayUnits().
Autodesk.Revit.Exceptions ArgumentOutOfRangeException A value passed for an enumeration argument is not a member of that enumeration
Autodesk.Revit.Exceptions ArgumentsInconsistentException currentDisplayUnit and desiredDisplayUnit have different dimensions.

See Also

ArchiLabs

Stop fighting Revit automation.

Build repeatable BIM design and documentation workflows with scripts, data, and AI in one place, without wrestling brittle one-off automations.

Try ArchiLabs →