Sample Code

This section provides sample applications that demonstrate key features and workflows of the HOOPS Exchange API. Each example highlights specific use cases, such as file conversion, metadata extraction, and geometry processing, serving as practical starting points for integrating the API into your projects.

While we aim to provide examples in both C and C#, some samples are currently available in only one language. Future updates will expand language coverage to include all key functionalities.

In the meantime, you can adapt existing examples to your preferred language, as the C# API mirrors the functionality of the C API through its bindings. Refer to the C# API Primer for guidance.

Description C/C++ C# Keywords
Adapt B-rep models to your needs yes yes B-Rep Geometry
Log CAD file events and errors no yes Logging Callbacks Errors
Manage cascaded attributes easily yes no Attributes Customization
Find collisions in CAD models yes no Collision Analysis Detection
Count parts in a structure no yes Structure Parts
Split assemblies into PRC files yes no PRC Assemblies Files
Generate PRC with geometry yes no PRC Geometry Tessellation
Create textured cubes in PRC yes yes PRC Cubes Visualization
Export features to XML yes yes Features XML Models
Convert CAD files seamlessly yes yes Conversion Files
Load CAD files step by step yes yes Loading Large Files
Handle multi-config CAD files yes no Configurations CAD
Visualize mesh data yes no Mesh Visualization
Use Exchange in .NET projects yes no Wrapper .NET
Convert PRC to XML format yes no PRC XML
View assembly hierarchy yes yes Assembly Hierarchy
Modify and sew B-reps yes no B-Rep Sewing
Break assemblies into components yes no Assemblies PRC Splitting
Convert CAD to Parasolid yes no Parasolid Translation

How to Build And Test Our Example Codes

Beforehand, make sure you have correctly prepared your environment for building and testing HOOPS Exchange. Follow the instruction in Set Up Your Environment for more information.

Since HOOPS Exchange 2025.4.0, we provide CMake support for our sample code.

You need CMake version 3.20.2 or higher.

The example code projects follow a typical CMake workflow. If you are familiar with CMake, no special steps are required. If you are new to CMake, we recommend the official tutorial from Kitware.

To learn more or to download CMake, visit the official website.

Check if you have CMake

You can check if CMake is installed by running the following command in your terminal or command prompt:

cmake --version

This will show the version of CMake on your system. If you do not have it, or if the version is lower than 3.20.2, you should install a newer version.

You can download the installer from the CMake downloads page. There are versions for Windows, macOS, and Linux.

Building sample code with the CMake UI

CMake has a graphical interface that can help you set up your project step by step. This is available on Windows, macOS, and Linux.

First, open the CMake application.

  • In the field Where is the source code, choose the folder that contains the sample code.
  • In the field Where to build the binaries, choose a different empty folder. This is where the build files will be created.

Click the Configure button. CMake will ask you which compiler or tool you want to use (see Supported Platforms). After configuration, you will see some options you can change if needed.

Click Generate to create the project files.

Now you can open the generated project in your IDE and build it there.

Building sample code from the command line (POSIX)

If you prefer to use the terminal, you can also run CMake from the command line.

First, create a new folder for the build:

$ mkdir build
$ cd build

Then run CMake with the path to the sample code:

$ cmake ../path/to/samples -DCMAKE_BUILD_TYPE=Release

If you want to choose a specific compiler or generator, you can add the -G option:

$ cmake ../path/to/samples -G "Visual Studio 17 2022"

Once CMake finishes, you can build the code with this command:

$ cmake --build . --config Release

CMake will automatically run the correct build tool, such as make, ninja, or msbuild, depending on what you selected.

After building, you will find the compiled sample programs in the folder named sample_bin/ at the root of your build directory.

B-Rep Adaptor

C/C++ samples/exchange/exchangesource/BrepAdaptor
C# csharp/samples/exchange/BRepAdaptor

B-Rep Adaptor shows how to make use of A3DAdaptAndReplaceAllBrepInModelFileAdvanced() to adapt B-rep models to your particular needs.

Callbacks Report

C# csharp/samples/exchange/CallbacksReport

This application initializes HOOPS Exchange, then load a CAD file. It writes the Exchange log to a file (or standard console output if not specified). It also implements the message, warning and error callbacks.

Cascaded Attributes

C/C++ samples/exchange/exchangesource/CascadedAttributes

This sample demonstrates how to programmatically set the mechanism of the cascaded attributes using HOOPS Exchange.

Collision Detection

C/C++ samples/exchange/exchangesource/Collision

This sample illustrates the collision detection feature in HOOPS Exchange. The sample reads an input CAD file and outputs collision status between representation items. The user may select which items are tested using their UUIDs; the output is available as a report file.

Count Part Instances

C# csharp/samples/exchange/CountPartInstances

This application initializes HOOPS Exchange, then walks the product structure to find all part instances. It writes the part instance count to a log file (or standard console output if not specified).

Import Multiple PRC Files

C/C++ samples/exchange/exchangesource/MultiplePRCFiles

This sample demonstrates how to programmatically create and read multiple PRC files from a CAD assembly using HOOPS Exchange. The input is the CAD assembly file path and a directory. The program generates multiple PRC files from this CAD assembly.

This mode is supported for the following formats: V4, V5, ProE, UG, SLDW. With other formats, only one PRC file is generated.

Create PRC B-Rep With Geometry

C/C++ samples/exchange/exchangesource/CreatePRCBrepWithGeometry

This sample demonstrates how to programmatically create a PRC file using HOOPS Exchange. The only input is the file path. The program generates a PRC file which contains a warped circle with a thick edge.

Create PRC Cubes

C/C++ samples/exchange/exchangesource/CreatePRCCubes
C# csharp/samples/exchange/CreatePRCCubes

This sample demonstrates how to create a PRC file with the Exchange API. The only input is the output file path. The program generates a PRC file containing a tessellated textured cube that is instantiated multiple times. The generated output also contains PMIs and Views, as well as links between markups, Views, and entities.

DumpFeatureTree

C/C++ samples/exchange/exchangesource/DumpFeatureTree
C# csharp/samples/exchange/DumpFeatureTree

This sample demonstrates how to traverse a model and capture its features in an XML file.

Import Export

C/C++ samples/exchange/exchangesource/ImportExport Tutorial
C# csharp/samples/exchange/ImportExport Tutorial

This sample demonstrates how to programmatically import a CAD model using HOOPS Exchange and convert it to another format.

For more information, see examples/import_export.rst.

Note

Experimental USD export

Since HOOPS Exchange 2025.4.0, we support exporting to USD as an experimental feature. The Import Export sample can be extended to provide this functionnality. For more information, see Extending the Import Export Sample.

Incremental Load

C/C++ samples/exchange/exchangesource/IncrementalLoad
C# csharp/samples/exchange/IncrementalLoad

This sample demonstrates two ways of loading a CAD file: normal loading and incremental loading (first the assembly tree, then the parts contained in the file). Using the incremental loading technique allows a more fine-grained approach, which is especially beneficial when dealing with huge files (e.g., for loading only specific items at a time rather than the whole file in one shot). The only input is the file path.

Load CAD File With Multiple Configurations

C/C++ samples/exchange/exchangesource/LoadMultiConfigCADFile

This sample demonstrates how to programmatically load CAD files that contain multiple configurations using HOOPS Exchange. The only input is the file path.

Mesh Viewer

C/C++ GitHub Write a CAD Viewer
C/C++ samples/exchange/exchangesource/Viewer  
C/C++ samples/exchange/exchangesource/DrawingViewer  

The Mesh Viewer example, added in HOOPS Exchange 2023 SP2 U1, demonstrates how to use the new usability API to access mesh data in representation models.

The Write a CAD Viewer tutorial provides more information about it.

.NET Wrapper

C/C++ samples/exchange/exchangesource/NetWrapper

This sample demonstrates how to use HOOPS Exchange with a .NET wrapper by converting any CAD file to XT.

PRC to XML

C/C++ samples/exchange/exchangesource/PRC2XML

Converts a PRC file to an XML representation.

Sew B-Rep

C/C++ samples/exchange/exchangesource/SewBrep

This sample demonstrates how to programmatically adapt B-rep models to particular needs using HOOPS Exchange.

The only input is the CAD file path.

  • Load a CAD file
  • Traverse the entire data structure
  • Call A3DSewBrep for each B-rep model
  • New modified data are populated
  • PRC is exported from the modified data

Shattered

C/C++ samples/exchange/exchangesource/Shattered

This sample demonstrates how to use the shattered mode in HOOPS Exchange. The input is the CAD assembly file path and a directory. The program generates multiple PRC files from this CAD assembly.

  • Load a CAD assembly
  • Extract all dependencies from the CAD assembly
  • Convert CAD part files to PRC
  • Convert CAD assembly files to PRC
  • Reload the full model into memory from the previously created PRC files.

TranslateToPkParts

C/C++ samples/exchange/exchangesource/TranslateToPkParts

This sample demonstrates how to use the Parasolid bridge in HOOPS Exchange to send the converted CAD data to Parasolid and then use the Parasolid APIs to perform advanced functions on the geometry, like healing, merge, simplify, sew, or accurate edges.

The input is the CAD file path and a directory plus the options. The program generates a Parasolid file from this CAD file. Please note that this sample won’t compile right away, specific things (detailed in the header of the source file) related to the Parasolid setup need to be done before running it.