vcUnit

vcUnit represents a single unit of measurement complete with a name, suffix and properties for describing linear mapping between canonical and unit values.

Unit Conversion

The conversion between canonical and unit values is as follows:

  • Canonical value to Unit value
    UnitValue := (Canonical - Offset) / Factor
  • Unit value to Canonical value
    CanonicalValue := UnitValue * Factor + Offset

Properties

Name Type Access Description
Factor Real RW/R If unit is built-in, gets conversion factor; otherwise defines conversion factor. That is, the size of unit in canonical units which must be larger than zero.
Group vcUnitGroup R Gets the unit group of unit, which is defined at the time of unit creation.
IsBuiltIn Boolean R Indicates if unit is built-in.
Name String RW/R If unit is built-in, gets the unit's name; otherwise defines the name of unit.
Offset Real RW/R If unit is built-in, gets zero-point offset; otherwise defines the canonical value at which the unit value is zero.
Suffix String RW/R If built-in, gets unit's suffix; otherwise defines the suffix of unit , which is displayed in GUI with property values.

Methods

Name Return Type Parameters Description
convertFromCanonical Real Real value Converts a given canonical value to a unit value, and then returns the unit value.
convertToCanonical Real Real value Converts a given unit value to a canonical value, and then returns the canonical value.
getConstantExpression String Real value Converts a given canonical value to a unit value, and then returns an expression of unit value with an appended unit specification.
getRelativeMagnitude Real Real magnitude Returns the size of unit in relation to a given magnitude using a logarithm of unit factor and a given magnitude which must be greater than zero.

Examples

Example. Convert unit values

from vcScript import *
 
def OnRun():
  comp = getComponent()
  prop = comp.getProperty("Temperature")
  unit = prop.Unit
  
  #convert to unit value
  unit_value = (prop.Value - unit.Offset)*unit.Factor
  
  #convert unit to canonical value
  canonical_value = unit_value * unit.Factor + unit.Offset
  print canonical_value