Units Struct - Accessing System and Display Units

The Units struct provides access to system global variables and some methods to get and set the System Units scale, type, and Display Units.

System Globals:

units.DisplayType

Gets/sets the current unit display type as a <name>.

Valid unit display types are:

#Generic #Metric #US #custom
units.MetricType

Gets/sets the current metric unit display type as a <name>.

Valid metric unit display types are:

#Millimeters #Centimeters #Meters #Kilometers
units.USType

Gets/sets the current US standard unit display type as a <name>.

Valid US standard unit display types are:

#Frac_In #Dec_In #Frac_Ft #Dec_Ft #Ft_Frac_In #Ft_Dec_In
units.USFrac

Gets/sets the current US fraction display type as a <name>.

Valid US fraction display types are:

#Frac_1_1 #Frac_1_2 #Frac_1_4 #Frac_1_8 #Frac_1_10 #Frac_1_16 #Frac_1_32 #Frac_1_64 #Frac_1_100 
units.CustomName 

Gets/sets the current custom unit name as a <string>.

units.CustomValue 

Gets/sets the current custom unit value as a <float>.

units.CustomUnit 

Gets/sets the current custom unit type as a <name>.

Valid custom unit display types are:

#Inches #Feet #Miles #Millimeters #Centimeters #Meters #Kilometers 
units.SystemScale 

Gets/sets the current system unit scale value as a <float>.

This is the value shown in Customize Units Setup > System Units Setup > System Units Scale group.

units.SystemType

Gets/sets the current system unit scale type as a <name>.

This is the unit shown in Customize > Units Setup > System Units Setup > System Units Scale group.

Valid system unit scale types are:

#Inches #Feet #Miles #Millimeters #Centimeters #Meters #Kilometers 

Methods:

units.formatValue <float> 

Returns a <string> value representing the <float> in the current unit scale.

This method can cause a string overflow, especially when the units are set to miles or kilometers.

If an overflow occurs a run-time error is thrown.

EXAMPLE

   units.DisplayType = #Generic
   -->#Generic
   units.SystemType = #inches
   -->#inches
   units.formatValue 123.45
   -->"123.45"
   units.DisplayType = #Metric
   -->#metric
   units.MetricType = #meters
   -->#meters
   units.formatValue 123.45
   -->"3.136m"
   units.MetricType = #centimeters
   -->#centimeters
   units.formatValue 123.45
   -->"313.563cm"
   units.DisplayType = #US
   -->#us
   units.USType = #ft_Frac_In
   -->#ft_Frac_In
   units.formatValue 123.45
   -->"10'3 14/32""
   units.USType = #Dec_Ft
   -->#dec_Ft
   units.formatValue 123.45
   -->"10.287'"
   units.DisplayType = #Custom
   --#custom
   units.formatValue 123.45
   -->"0.016FL"
units.decodeValue <string> 

Parses <string> using the current unit settings and returns a <float>.

A run-time error is thrown if an error occurs in the parsing of the string.

This is the inverse function of units.formatValue() described above.

The back and forth conversion of values can lead to precision loss due to rounding errors.

EXAMPLE

   units.DisplayType = #Generic
   -->#Generic
   units.decodeValue "3.136m"
   -->123.465
   units.decodeValue "313.563cm"
   -->123.45
   units.decodeValue "10'3 14/32\""
   -->123.438
   units.decodeValue "10.287'"
   -->123.444
   units.decodeValue "0.016FL"
   -->126.72