Hide menu
Loading...
Searching...
No Matches
Import Example

Table of Contents

Reads an external CAD file and translates its contents into a 3D model in memory.

Overview

The Import Example shows how to import models from files of different formats and manipulate its data using the ModelData_Model class.

In this example we create a Reader which allows us to read specific file format. Next, we use the Reader to transfer model data to a ModelData_Model object.

Main Function

At the moment CAD Exchanger SDK supports a big variety of model types. Here we will import a model from a STEP file as one of the most popular format. Our main function will have the following structure:

STEP_Reader aReader;
STEP_ReaderParameters& aReaderParams = aReader.Parameters();
aReaderParams.PreferredBRepRepresentationType() = STEP_ReaderParameters::AdvancedBRep;
  • Read a STEP file and transfer its data to a ModelData_Model object:
    ModelData_Model aModel;
    if (!aReader.ReadFile (aSource)) {
    cerr << "Failed to read the file " << aSource << endl;
    return 1;
    }
    if (!aReader.Transfer (aModel)) {
    cerr << "Failed to transfer model data to specified format" << endl;
    return 1;
    }
  • As a result now we have an access to a ModelData_Model object which we can use in further conversions and operations:
cout << "Model name: " << aModel.Name().ToUTF8().Data() << endl;
cout << "Number of roots: " << aModel.NumberOfRoots() << endl;
if (!ModelData_ModelWriter().Write (aModel, aDest)) {
cerr << "Failed to write the file " << aDest << endl;
return 1;
}

Summary

CAD Exchanger SDK provides a lot of packages for model data conversion. It's possible to read, write and transfer almost every existing model data format simply using algorithm described above.

To learn more about conversion possibilities please visit the Converter Details.

Files