CAD Exchanger SDK
Examples

Introduction

CAD Exchanger SDK includes a set of C++, C# and Java examples demonstrating its functionality. The examples are located in the ${install_dir}/examples subdirectory.

The examples are provided under a permissive Modified BSD License. You may insert their source code into your application and modify as needed.

Prerequisites

Before launching examples make sure you:

  • Activate a license key received during evaluation (or after purchasing a commercial license);
  • Set your development environment. Refer to Setting up development environment for common settings and language-specific sections below.
Note
Whenever you modify an example code to use any other supported converter, change between 32 and 64 bit architectures, switch between debug and release modes make sure you update environment settings and (optionally) the example code to reflect the changes.

List of Examples

Links in the below table lead to C++ versions of respective example. For other language just navigate into corresponding subfolder in the SDK package.

Select any example that most closely matches your target use case and introduce modifications specific to your case.

Example Purpose
General Example Demonstrates how to simply convert CAD files with the help of CAD Exchanger SDK
Model Explorer Demonstrates how to explore imported model contents
Assembly Creation Demonstrates how to create an assembly of sub-assemblies and parts of solid primitives and to export to target format
Meshing Example Demonstrates how to create polygonal representations using computational meshers
Progress Status Example * Demonstrates how to integrate support of progress status update
CAD Exchanger Viewer Example * Demonstrates how to use and setup CAD Exchanger viewer
B-Rep Bottom-up Creation Example * Demonstrates how to create B-Rep representation bottom-up

(*) Available in C++ only.

C++ Examples

C++ examples are located in the subfolder ./examples/cxx.

Note
Save the license key file you received for your evaluation program as ${install_dir}/examples/cxx/cadex_license.cxx. When you become a customer you will substitute it with a commercial license key.

Building

C++ examples are provided with cmake-based configuration files. To build examples download the cmake tool from cmake.org.

Building with Microsoft Visual Studio on Windows

To build C++ examples open cmake-gui, choose the example's subdirectory, choose build directory and press "Configure" button.

cmake-gui_msvc_ide_step1.png

Next specify required Visual Studio version (e.g. Visual Studio 15 2017 Win64).

cmake-gui_msvc_ide_step2.png

When configuring has been done press "Generate" button.

cmake-gui_msvc_ide_step3.png

This will create Visual Studio project and solution files in the build subdirectory.

Note
For building Qt-based examples set QT_ROOT_DIR entry to Qt 5 installation folder and reconfigure project again.

Building with GNU Makefiles

On Linux or MacOS, to build an example with the help of GNU make, use respective generator with cmake:

cd /dev/cadexchanger/3.4.2/examples/cxx/cadexgen
cmake -H. -Bbuild -G "Unix Makefiles"

Note
To get the list of supported generators invoke cmake --help.
To build a debug configuration add the switch -DCMAKE_BUILD_TYPE=Debug.
For building Qt-based examples add the switch -DQT_ROOT_DIR=<path_to_qt_directory>

To run built examples, you should add the path to CAD Exchanger dynamic libraries directory to the environment variable LD_LIBRARY_PATH on Linux and DYLD_LIBRARY_PATH on MacOS.

Note
Pay attention that you need to set respective directories depending on your particular configuration, including target architecture (x86 or x64), compiler (e.g. gcc4 or clang7), and mode (release or debug). Refer to Setting up development environment for detailed descriptions of subfolders.

C# Examples

C# examples are located in the subfolder ./examples/csharp.

Note
Insert contents of the license key your received for your evaluation period into your example code at the following line:
// insert the license key here!
//string theKey = "";

Building with Microsoft Visual Studio

There are two ways to configure C# examples:

  1. Cmake-based. Generation of C# projects is exactly the same as generation of C++ projects for Visual Studio (see Building with Microsoft Visual Studio on Windows).
    Note
    Cmake 3.8.0 or higher is required to generate C# projects for Visual Studio.
  2. Visual Studio project files.
    • Open a selected example's project file (*.csproj).
    • By default, the example project files are configured to target 64-bit platforms and to use 64-bit assemblies located in ./csharp/win64 directory. If you need to enforce using 32-bit configuration then add a respective directory with 32-bit native C++ libraries (e.g. ./win32/vc14/bin) and update assembly references (e.g. CadExCoreNet, CadExParaNet, etc) by browsing the subdirectory corresponding to 32-bit configuration (e.g. ./csharp/win32).
    • If you modify the example by adding some new format then make sure you add a respective assembly to the list of references (e.g. CadExVRMLNet if you integrate the VRML converter).
    • Build and run the example.

Java Examples

Java examples are located in the subfolder ./examples/java.

Note
Insert contents of the license key you received for your evaluation period into your example code at the following line:
// insert the license key here!
//string theKey = "";

Building with Eclipse

Note
Following instructions are applicable to any supported Operating System.
  • Create new Java project.
  • Add new class and copy contents of desired CadEx example to it.
  • Pay attention to class static initializer: System.loadLibrary() calls actually are aligned with a list of required CadEx JARs.
  • In the "Project Properties" dialog choose the "Java Build Path" option, go to "Libraries" tab and press "Add External JARs". Navigate to the 'java' subdirectory in CAD Exchanger package (e.g. C:/dev/cadexchanger/java) and select required JARs (e.g. CadExCoreJava.jar, CadExParaJava.jar, CadExSTEPJava.jar).
eclipse_java_gen_jar.png

Launch configuration

  • Open the "Run As" dialog to access launch configuration.
  • Select the "Arguments" tab and look for "VM Arguments" window. Add the 'java.library.path' argument with the path to CAD Exchanger native libraries appropriate for your OS. E.g. for Windows:
    -Djava.library.path=C:/dev/cadexchanger/win64/vc12/bin
Note
For Linux or MacOS the path would be like '../cadexchanger/mac64/clang7/lib'.
You are free to choose any compiler specific subfolder, but it's recommended to use the one corresponding to latest version (e.g. vc12 aka Visual Studio 2013 at the time of this writing).
eclipse_java_gen_arg.png
Note
If you wish to use debug versions of libraries, then the path should end with 'd' suffix (bind or libd). You would also need to append suffix to all native libraries names in your class static initializer:
System.loadLibrary("CadExCored");
  • Pay attention to "Program arguments" window: some examples require them (e.g. 'cadexgen' takes two path arguments).
  • Navigate to "Environment" tab. Here we need to extend the OS specific libraries environment variable with the same path as in previous step. E.g. for Windows this is a 'PATH' variable:
    eclipse_java_gen_var.png

For Linux the variable is 'LD_LIBRARY_PATH' and 'DYLD_LIBRARY_PATH' for MacOS.

  • You should now be able to run your Java application.