InterOp:Connect/Using Units
From DocR23
InterOp Connect provides functionality to manage units of measurement for a document. InterOp Connect maintains the information about the units of a document during the data translation. For example, if a source document is modeled in millimeters, Connect attempts to create a destination document with the same units of measurement. Connect also provides the capability to manually configure the unit for the destination document. If different units are specified for the source and destination documents, the model will automatically be scaled during the data translation process.
Note:
- By default InterOp creates destination documents in the same unit of measurement as the source document, however, there are some exceptions.
- The destination unit should always be set to match the application unit of measurement to avoid further scaling.
- If the application is not dependent on units, set mm as the unit for ACIS destination documents.
- If the application is not dependent on units, set meter as the unit for Parasolid destination documents.
Contents |
Querying the Document's Unit
The SPAIUnit class can be used to query the source and destination documents' unit.
If the unit is queried using GetUnit of document immediately after calling SetUnit of document, then GetUnit will return the unit set by SetUnit.
For a source document created from a file (where SetUnit cannot be called), the GetUnit of document can be called after a call to GetHeaderInfo. In this case, GetUnit will return the unit of the source document as read from the file during GetHeaderInfo. The following example illustrates how to query and display the unit of the source document created from a file:
#include "SPAIDocument.h" #include "SPAIDocumentHeaderInfo.h" #include "SPAIConverter.h" #include "SPAIUnit.h" #include "SPAIResult.h" void main() { SPAIResult result=SPAX_S_OK; SPAIDocument src("C:/model_in_inch.igs"); SPAIDocumentHeaderInfo info; result &= src.GetHeaderInfo(info); SPAIUnit srcUnit; result &= src.GetUnit( srcUnit); // srcUnit should be inch. printf("Input Document Unit : %s\n", (const char*)srcUnit); // Based on unit of source document, unit of destination document can be set here. SPAIDocument dst("C:/model.sat"); SPAIConverter converter; result&=converter.Convert(src, dst); return; }
For the destination document (created for output as a file or native entities), GetUnit of document can also be called after the translation. In this case, GetUnit will return the unit of the destination document as set during translation. The following example illustrates how to query and display the destination document unit:
#include "SPAIDocument.h" #include "SPAIConverter.h" #include "SPAIUnit.h" #include "SPAIResult.h" void main() { SPAIResult result=SPAX_S_OK; SPAIDocument src("C:/model_in_inch.igs"); SPAIDocument dst("C:/model.sat"); SPAIConverter converter; result&=converter.Convert(src, dst); // Get Destination Document Unit. // Because Connect preserves the unit of the source document by default, the destination // document should be inch. SPAIUnit unit; result&=dst.GetUnit(unit); printf("Output Document Unit : %s\n", (const char*)unit); return; }
Setting the Document Unit
The SPAIUnit class can be used to set the document unit. Call SetUnit of document before calling Convert.
For the source document, SetUnit can be called only for the source document created from native entities. If SetUnit is called on a source document created from a file, the unit requested by SetUnit will be ignored and the unit saved in the source document file will be used during the translation. The following example illustrates how to set the unit of a source ACIS document created from live ACIS entities.
#include "SPAIAcisDocument.h" #include "SPAIConverter.h" #include "SPAIUnit.h" #include "SPAIResult.h" void main() { SPAIResult result=SPAX_S_OK; ENTITY_LIST acisEntities; FILE* pAcisFile=fopen( "C:/model_in_inch.sat", "r"); outcome res = api_restore_entity_list(pAcisFile, true, acisEntities); SPAIAcisDocument src(&acisEntities); // Though the unit of the SAT file is inch, we are setting the unit of the ACIS document as foot. // During translation, the unit of the source document will be taken as foot. SPAIUnit srcUnit(SPAIUnitFoot); src.SetUnit( srcUnit); SPAIDocument dst( "C:/model.igs"); SPAIConverter converter; result&=converter.Convert(src, dst); return; }
For the destination document (created for output as a file or native entities), SetUnit can be called before translation and then the destination document file or destination document entities will be created in the unit set by SetUnit. The following example illustrates how to set inches as the destination unit:
#include "SPAIDocument.h" #include "SPAIConverter.h" #include "SPAIUnit.h" #include "SPAIResult.h" void main() { SPAIResult result=SPAX_S_OK; SPAIDocument src("C:/model_in_foot.igs"); SPAIDocument dst("C:/model_in_inch.sat"); // Select Destination Document Unit as Inch. SPAIUnit requestedUnit(SPAIUnitInch); result&=dst.SetUnit(requestedUnit); //Convert will correctly scale the source file in foot unit to the //destination document in inch unit. SPAIConverter converter; result&=converter.Convert(src, dst); return; }
Supported Units
SPAIUnitValue is an enumeration that defines the units supported by SPAIUnit.
| SPAIUnit Value | Unit |
|---|---|
| SPAIUnitUnknown | Default value for the SPAIUnit object. If the destination document unit is SPAIUnitUnknown, then no scaling occurs and the unit written to the destination document is the same as the source document. |
| SPAIUnitModel | If the document unit is specified as SPAIUnitModel, then the default unit associated with the destination document is used. Refer to Table. SPAIUnitModel Reference for more details. |
| SPAIUnitNanometer | nanometer |
| SPAIUnitMicrometer | micrometer |
| SPAIUnitMillimeter | millimeter |
| SPAIUnitCentimeter | centimeter |
| SPAIUnitDecimeter | decimeter |
| SPAIUnitMeter | meter |
| SPAIUnitKilometer | kilometer |
| SPAIUnitInch | inch |
| SPAIUnitFoot | foot |
| SPAIUnitMile | mile |
| SPAIUnitMilliInch | milli-inch |
| SPAIUnitMicroInch | micro-inch |
Fixed Destination Units
Note that for some systems, the destination unit values are fixed. These are:
| CATIA V5 | millimeter |
| VDA | millimeter |
| IGES | any except decimeter and nanometer |
If you set the destination unit for these systems to anything other than these values or to SPAIUnitModel, then the SetUnit method fails and returns the invalid write units error code SPAX_E_INVALID_WRITE_LENGTH_UNIT.
For IGES write, if you set the destination unit to SPAIUnitDecimeter or SPAIUnitNanometer, then the SetUnit method fails and returns the invalid write units error code SPAX_E_INVALID_WRITE_LENGTH_UNIT.
SPAIUnitModel Reference
The following table lists the units that are used for various systems when SPAIUnitModel is used as the destination unit.
| System | Unit |
|---|---|
| ACIS | unit present in save_info |
| CATIA V4 | millimeter |
| CATIA V5 | millimeter |
| IGES | millimeter |
| NX | millimeter |
| PARASOLID | meter |
| Pro/E | millimeter |
| STEP | millimeter |
| VDA | millimeter |
| INVENTOR | millimeter or inch |
| SOLIDWORKS | millimeter or meter |
Unit Sample
This sample demonstrates the use of setting units for an output file during translation.
Usage
Unit -i file -iformat format -o file -oformat format -unit unit
Options
-i : input file -o : output file -iformat : input format -oformat : output format -unit : output model unit