Successful Simulations

This page is for topics related to using the OpenSim API.

Table of Contents

Getting Started

The OpenSim Developer's Guide is very detailed and the tug of war example in section 2.1 covers a lot of ground. Even if your C++ skills are a bit rusty or you've only programmed in other languages, this is broken down into nice little exercises on a beginner level.

Creating a Solution in Visual C++ 2008 Express Edition

If you're unfamiliar with CMake, steps 1-5 in the instructions for building an OpenSim plug in are a good place to start. Substitute "OpenSim 1.6" with the current version.

Once you have a solution there are a few more things to check in Visual C++.

Helpful Hints for Frustrating Problems

If you're getting errors related to DLL's early in your program, check your system's Path to make sure you don't have conflicting versions of OpenSim. When all else fails, rebuild in CMake

Example Programs

The easiest way to write an API program is to start with something that works and modify it. Here are details on some of the programs that can be found in the download section.

These programs are shared in good faith. Please give credit where credit is due and pay it forward.

A Simple Muscle Modifier

What it Does and Why

This program takes a model and scales the value of each muscle's max_isometric_force by a constant factor. It was developed because there was a need to quickly boost the strength of all the muscles in a model consistently so that it would be strong enough to simulate walking with CMC.

Where to Find It

The downloads section of the Modeler's Kitchen under OpenSim API Programs > Model Modifying Programs >

How to Use It

The zip file contains both the executable if you just want to use it as is, and the .cpp source code if you want to use this as a basis for your own main program. If you're using the .exe give it three arguments in the command window: the filename of the original model, the filename of the modified model, and the scale factor. For example, if you want to scale a model named mySimpleBlockModel.osim by a factor of 1.5 to create a new model called myStrongerBlockModel.osim, and executable muscleModifier_ScaleForce.exe and your original model are in the C:\ directory, your command line would look like this:

C:\ muscleModifier_ScaleForce.exe mySimpleBlockModel.osim myStrongerBlockModel.osim 1.5

And the messages should look like this:

This program includes software developed by the
Apache Software Foundation (

Loaded model mySimpleModel from file mySimpleBlockModel.osim
muscle1, muscle type: Schutte1993Muscle
muscle1 scaled to new max_isometic_force.  
muscle2, muscle type: Thelen2003Muscle
muscle2 scaled to new max_isometic_force.  
Modified model saved to file: myStrongerBlockModel.osim

If you'd rather build the code and run it in Visual C++ 2008, you'll have to make a couple changes since it's written to take command line arguments. This can be done by hard coding in the three arguments, and taking out the stuff in the () right after main. Or, right click on the name of the solution in the solution explorer, click Properties, go to Configuration Properties > Debugging, then change Command Arguments to the three things you'd type after the executable.

Who Made It

Edith Arnold (not trained as a software developer, got started with the tug of war example and some rusty C++ knowledge) and Ajay Seth (one of the lead developers for OpenSim).

User Experience

Note from Sam Hamner: This is only valid for Windows machines. I was only able to get the executable to run once I installed the file in the "bin" directory of my OpenSim installation (e.g., C:\OpenSim2.2.1\bin). Otherwise, it had trouble linking to osimCommon.dll, even if the bin directory was added to my path.

Note from Sam: THIS DID NOT WORK WITH 2.4

Next Example

What it Does and Why

Fill in the blank.

Where to Find It

Fill in the blank.

How to Use It

Fill in the blank.

Who Made It

Tell us who you are and what knowledge you had coming into making this.

ApiAdventures (last edited 2016-05-04 22:06:30 by localhost)