Program Custom Exporter with SimMechanics Link API

Including, Linking to, and Calling the API Function Library

In the following procedures, replace:

  • matlabroot with the root of your MATLAB® installation.

  • ARCH with the specific operating system architecture abbreviation for your system (for example, win32 for 32-bit Windows).

Including and Using the API Header File

To write your C/C++ custom exporter module, use the C header file located in matlabroot/toolbox/physmod/smlink/api/include/.

This header file contains the function definitions that you follow to call the SimMechanics™ Link API functions from your module. Include this header file in your module C/C++ source code.

Compiling and Linking the Custom Exporter Module

In addition to linking your custom module to the SimMechanics Link API, consult your CAD platform's API documentation to determine requirements for linking to the platform's API.

On Windows Platforms.  After you compile your module, link it to the binary API function library located in matlabroot\toolbox\physmod\smlink\api\lib\.

On UNIX, LINUX, and Mac Platforms.  After you compile your module, link it to the binary API function library:

matlabroot/bin/ARCH/libmwpmi_api.OS-SPECIFIC-EXTENSION

OS-SPECIFIC-EXTENSION is the API file extension specific to your operating system.

Executing the Custom Exporter Module

To determine if you need to include your CAD platform API on the path, consult your CAD platform API documentation.

On Windows.  Before you start execution of the module, verify that the folder matlabroot\bin\ARCH\ is on the path.

On UNIX, LINUX, and Mac Platforms.  Before you start execution of the module, verify that the folder matlabroot/bin/ARCH/ is included in the system path environment variable LD_LIBRARY_PATH.

Locating API Code Examples

You can find API examples in this folder:

matlabroot/toolbox/physmod/smlink/api/example/

The subfolder, cadapi_example/, contains CAD-based examples.

A Custom Exporter Module Example

The folder matlabroot/toolbox/physmod/smlink/api/example/cadapi_example/ contains a simple C++ example of a custom module based on the API, cadapi_example.cpp.

  • The example custom module converts two CAD parts with one constraint into two SimMechanics bodies and one joint and then writes the result to a Physical Modeling XML file.

  • The example program defines the CAD assembly data internally, rather than taking the data from a CAD platform through the platform API. Compared to the figure Custom Exporter Module Communicates with APIs (Detail), the leftmost portion of the diagram is missing.

  • To extend the example module to process real assembly data, add code that calls a CAD platform's API for assembly data to replace the internally defined data.

Was this topic helpful?