UnitsOfMeasure is an object that helps conversion of values from and to Inventor’s database units. Inventor internally always uses cm (centimeters) for length, radians for angle, kg (kilograms) for mass and seconds for time. But the user can choose to work in another units, which can be set by this object. The various API methods, for example, creation of sketch entities, always take values that are in the internal database units. When a SketchPoint object is created whose coordinates are say (5,5), the values are always in cm even though the user may have his default units set to inches. Another example is the creation of parameters using the API, the methods always take the values of the parameters in the internal database units.
Consider the scenario of a program that accepts new parameter values from an end-user using a form and passes this value to a method that updates the parameter value. The end-user assumes that the values that he enters are in the default units that he has set up and it would not be intuitive to ask the user to convert the values to the internal database units before passing it on to the API method that updates the parameter value.
The UnitsOfMeasure object is very useful, in this case, to allow conversion from one unit system to the other. This object supports the following methods to help convert values and strings from one unit type to another:
1. GetStringFromType(UnitsType as UnitsTypeEnum) as String
This method returns the string representation of the unit type for the UnitTypeEnum parameter that is passed in. For example, when kCentimeterLengthUnits is supplied, "centimeter" is returned. The items in the list box on the right are displayed by making use of this method.
2. GetTypeFromString(UnitsString As String) As UnitsTypeEnum
This method returns the reverse of the above method, i.e. it returns the UnitTypeEnum for the string representation that is passed in. For example, when centimeter or "cm" is passed in, kCentimeterLengthUnits is returned.
3. GetStringFromValue(Value As Double, UnitsSpecifier) As String
This method returns the value along with the units for the value and the unit type in which you want the returned value to be specified in. The unit type of the Value parameter is the internal units that Inventor uses and are converted to the desired unit type as specified by the UnitsSpecifier parameter, which can be a string or the UnitsTypeEnum. For example, if parameters 2.0 and "in" (or "inches" or kInchLengthUnits) are passed in, the string that would be returned is "0.787 in".
4. GetValueFromExpression(Expression As String, UnitsSpecifier) As Double
When an expression is passed in, this method returns the value in the internal units, the UnitsSpecifier is used to indicate the unit type of any number that is part of the string and which doesn't have a string next to it to indicate its unit type. For example, if the string " 2 + 3 cm" and kInchLengthUnits is passed in, the unit type of 2 is inches and so the returned value would be 8.08 (the equivalent of 2in + 3cm in cm units).
The UnitsOfMeasure object can be queried from the Document object
'get the units of measure object
oUOM = oDoc.UnitsOfMeasure