Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

As of version 3.0, OpenSim comes with a built in scripting shell that allows user access to the OpenSim API for loading, editing, and building models, running tools, plotting results, and more. The syntax for the scripting shell in the GUI is Python.

 

Table of Contents

What's Available?

  • Access to the API for model editing and building
  • Access to the tools for processing and workflow batch processing
  • Access to most of the commands available from the OpenSim application menu and most of the selections tasks you can currently perform in the GUI
  • A streamlined interface to the plotter so that you can easily create, customize and export curves from the plotter.  
  • Limited access to the graphics window (e.g. selection and camera control)

Limitations  

Some internal SimTK classes (that belong to the SimTK namespace and Simbody internal functionality) are not available for construction, but the most commonly used classes are available as of version 3.1 (SimTK::Vec3, Vector, Mat33, State, Inertia
  • )

Getting Started

 

  1. Launch OpenSim and select Window > ScriptingShell to bring up the scripting window. This will display the main scripting shell window ("Jython Interactive Console") and the "Command History" of executed scripting commands.
     
  2. Select Scripts > Open... (Open > Browse for file... prior to OpenSim 3.1). Find the Scripts folder located in the directory where you installed OpenSim. There are many example scripts included with the OpenSim distribution. You can review these to get an idea of the capabilities of scripting or you can modify them to streamline the workflow of your own research. 
     
  3. Choose "testVisuals.py". The script will open in the OpenSim GUI's file editor. This script demonstrates how you can control visualization via scripting. The script loads a model ("gait2392_simbody"), changes the color of the pelvis, makes the right femur transparent, and aligns the model view with the x axis.
     
  4. To run the script hit F5, with the script open. Alternately, you can choose Scripts > Run Current Script.
     
  5. Go to the Scripting Shell Window and review the Command History, on the right hand side of the window. This will show you all of the scripting commands that were executed. Review the commands that performed each of the actions in the testVisuals script.
     
  6. Try executing another script command to change the opacity or color of the pelvis. Enter the commands at the prompt >>>. You can copy and paste lines of code to test individual commands.
     
  7. Try doing the same thing by modifying the testVisuals.py script. Find the "Scripts" folder in your OpenSim Install directory, open the file with a text editor (e.g. Notepad++), and add the command. Save the script with a new name (e.g. myTestVisuals.py). Return to OpenSim and try out the new script. You can run the script directly by selecting Scripts -> Run... and navigating to your script. Does it perform the function you expect? 
     
  8. Now try running, reviewing, and modifying the other example scripts included with your OpenSim distribution. The full list is below.
     
  9. Learn more about scripting in the section on Common Scripting Commands.

...