Reading (importing) and writing (exporting) files are the mainstream scenarios when using CAD Exchanger SDK. This can be the simplest way to integrate support of a new format into your application if it can already parse some format. For instance, if your application can parse STL files and you consider adding support of the IGES format then you can read IGES files and convert them to temporary STL files with the help of CAD Exchanger, and then parse those STL files using your existing code.
There are two primary ways to handle reading and writing in CAD Exchanger. ModelData_ModelReader and ModelData_ModelWriter classes can be used as single points of entry, capable of handling every format supported by CAD Exchanger. Alternatively, format-specific readers and writers may be used to get finer control over the import and export processes. Each format's classes are designated by a corresponding prefix, for instance JT_, ACIS_, IGES_, etc - refer to General Conventions for naming conventions.
Refer to Supported Formats for details on the supported scope for each format.
ModelData_ModelReader is the primary class for reading files, especially when import of multiple formats is needed. The usage is simple, one just has to call a single function with the path to the file that should be read and the target ModelData_Model instance, this reader itself determines what format the file is and performs the import correspondingly.
The ModelData_Model object is populated with the contents imported from the file being read. The model is not cleaned up before conversion, therefore a few files can be accumulated in the same model.
Alternatively, if the client application needs to have tighter control of the reading process, it's possible to use readers of individual formats, like so:
Note that reading a file that way requires the invocation of two functions:
ModelData_ModelWriter the primary way of writing 3D data to various formats. Similarly to the import one only has to call a single function specifying the file path and the writer automatically determines how to export the model based on the file extension. Once again, this is particularly useful if export to multiple formats is utilized in the same workflow.
Analogously to import, it's also possible to export models to specific formats using per-format writer classes:
Symmetrically to reading a file, writing a file consists of two steps:
Both universal and format-specific readers and writers support progress status update. The examples below demonstrates how to add observers to an internal progress status object:
When using format-specific readers and writers the progress status needs to be broken into scopes to make sure the status is filled up continuously across both stages of the import:
For details refer to Progress Status Support and Progress Bar Example.
Refer to Conversion, Progress Bar Example.