By Barbara Han
Issue
Parameter object has ModelValue, and Value properties, but they return the evaluation of the parameter in database units. Expression property returns a string including display unit, for example "10 mm", but what I want is just "10". Please suggest the way for getting the evaluation of the parameter in drawing display unit when you don't know what database unit this parameter uses.
Solution
UnitsOfMeasure.ConvertUnits() method can convert a value from one unit to another. Here is a sample to call ConvertUnits:
displayVaule = UOM.ConvertUnits(parameter1.Value, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kDefaultDisplayLengthUnits)
If you don't know which database unit to use, you can call GetDatabaseUnitsFromExpression method to get the database unit string, then call GetTypeFromString method to convert the string to UnitsTypeEnum value. Below is the VB.NET sample code that does it:
Sub parameterInfo()
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim para As Parameter
Dim UOM As UnitsOfMeasure
UOM = oDoc.UnitsOfMeasure
For Each para In oDoc.ComponentDefinition.Parameters
Debug.Print("Expression is " + para.Expression)
Debug.Print("Display unit is " + para.Units)
Debug.Print("ModelVaule is " + para.ModelValue.ToString)
Debug.Print("Value is " + para.Value.ToString)
Dim displayValue As String
displayValue = UOM.ConvertUnits(para.Value, _
UOM.GetTypeFromString(UOM.GetDatabaseUnitsFromExpression( _
para.Expression, para.Units)), _
para.Units)
Debug.Print("Display value is " + displayValue)
Next
End Sub
Below is a sample output:
Expression is 1.105 in
Display unit is in
ModelVaule is 2.80629415684689
Value is 2.80629415684689
Display value is 1.10484021923106