How are units represented in HOOPS Exchange ?
All units inside of PRC files are stored with decimal numbers, representing multiples of mm.
So for example, a meter will correspond to a value of 1000 while an inch is represented by 25.4
How can I determine a model’s global unit?
It’s possible to have multiple different units used inside of the same model, so that’s why the ModelFile and each ProductOccurrence can have their own unit (see both A3DAsmModelFileData::m_dUnit and A3DAsmProductOccurrenceData::m_dUnit).
To find the one global to the whole model, you’ll need to browse through its model file and sub-POs and find the first one for which m_bUnitFromCAD is set to true.
That’s basically what the function A3DAsmModelFileGetUnit (introduced since HE 2019) does.
Be careful because the model unit found may look slightly different from what is rendered if a scale is also set inside of the A3DTopoContextData.
Why does values do not correspond to my part unit?
Because the HOOPS Exchange API is storing all values (for both brep and tessellation) in mm.
So to retrieve the value expressed in the corresponding part unit, it is required to apply all the scales that are present in the whole transformation chain (see A3DAsmProductOccurrenceData::m_pLocation).
Why my unit is different after an export to another format ?
It all depends of the format used, different cases are possible:
- Some may just do not support the concept of units at all (especially tessellated ones, like OBJ or STL).
- Others might be using some session variable (meaning that values are in fact converted on the fly depending on the selected unit). So nothing is actually stored inside of the CAD file.
- Finally remaining ones could just use a specific unit set as default.
So here’s a non-exhaustive list of which unit are used by default for most common formats:
- CatiaV5: mm
- CatiaV4: mm / inches
- SolidWorks: m
- STEP: mm
- IGES: mm
- Inventor: cm
- ACIS: cm
- Parasolid: m
- I-deas: m
- OBJ: no unit
- STL : no unit
- U3D: no unit
- CGR: no unit
- VRML: (the convention is mm, but nothing has been clearly defined)
How can I overwrite units inside of a PRC file?
The easiest and fastest way to proceed is to create a new modelFile (with the A3DAsmModelFileCreate function) or to edit the root PO (you can use A3DAsmProductOccurrenceEdit for example), by setting m_bUnitFromCAD to true and put the desired m_dUnit (defined as a mm multiple).
Please find below a code sample as an example:
A3DAsmModelFileData sNewMFData; A3D_INITIALIZE_DATA(A3DAsmModelFileData, sNewMFData); sNewMFData.m_uiPOccurrencesSize = 1; sNewMFData.m_ppPOccurrences = new A3DAsmProductOccurrence*; sNewMFData.m_ppPOccurrences = pRootPO; sNewMFData.m_bUnitFromCAD = TRUE; sNewMFData.m_dUnit = dDstUnit; iRet = A3DAsmModelFileCreate(&sNewMFData, ppModelFile);