convertUnit
The convertUnit
function is used to convert an attribute value to a target unit
Syntax
c4i:convertUnit(value, targetUnitId [, errorsAsWarnings])
Parameters
value
The XPath to a XML Value node containing the attribute value and its unit
targetUnitId
The ID of the STEP Unit to convert to
errorsAsWarnings (optional)
If set to true, conversion errors will simply be logged instead of stopping the process
Return value
The converted value.
Thrown exceptions
UnsupportedOperationException
If there is no known conversion between the two units and errorsAsWarnings not set to true
IllegalArgumentException
If there is no unit for the given ID and errorsAsWarnings not set to true
Example
Given the following STEP XML :
<STEP-ProductInformation>
<UnitList>
<Unit ID="unece.unit.MMT">
<Name>mm</Name>
<UnitConversion BaseUnitID="unece.unit.MTR" Factor=".001" Offset="0"/>
</Unit>
<Unit ID="unece.unit.CMT">
<Name>cm</Name>
<UnitConversion BaseUnitID="unece.unit.MTR" Factor="0.01" Offset="0"/>
</Unit>
<Unit ID="unece.unit.MTR">
<Name>m</Name>
</Unit>
</UnitList>
<AttributeList>
<Attribute ID="Length">
<UnitLink UnitID="unece.unit.MTR"/>
<UnitLink UnitID="unece.unit.CMT"/>
<UnitLink UnitID="unece.unit.MMT"/>
</Attribute>
</AttributeList>
<Products>
<Product UserTypeID="PROD_ARTICLE" ID="123">
<Name>Test Product</Name>
<Values>
<Value AttributeID="Length" UnitID="unece.unit.MMT">12</Value>
</Values>
</Product>
</Products>
</STEP-ProductInformation>
The following YAML configuration will produce the following output :
c4i:convertUnit(Values/Value[@AttributeID="Length"], "unece.unit.MTR"): length
length : 0.012