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?
|
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
|
|
...
- You can change the location of the Scripts directory by going to Edit > Preferences and changing the directory under the "ScriptsPath" option (see User Preferences for more information).
- Directories are relative to the OpenSim installation Directory (e.g. Specifying "MyScripts" will look for scripts in the folder C:\ProgramFiles\OpenSim3.0\MyScripts if you installed OpenSim in the folder C:\ProgramFiles\OpenSim3.0).
- Note that you have to restart OpenSim for the change to take place.
- After loading a script, variables defined in the script are available for future reference
- A panel to echo commands and files executed in the scripting shell is available (the "Command History"). You can clear the command history by right clicking in the window and selecting "Clear".
- If there are errors in running a script from file, you can view the corresponding error messages by clicking on the red error icon in the bottom right of the OpenSim screen, and then selecting "Show Details"
- In the GUI scripting shell, code executed as part of for loops or if statements is controlled by indentation, rather than braces as in C++ or the for/end convention in Matlab. Otherwise, at the ScriptingShell command prompt, you must enter one line at a time.
Interacting with the GUI (including the Plotter)
In the GUI scripting shell, we've provided a set of commands that allow you to easily perform some basic plotting functionality. This includes adding a plot window, adding curves, changing the legend, plotting from file, exporting the plot, etc.
https://simtk.org/api_docs/opensim/gui_docs/org/opensim/console/OpenSimPlotter.html
These commands are exercised in the examples "plotMuscleFiberLengthAgainstFile.py" and "plotMuscleMomentArmAgainstMotion.py".
There are additional advanced commands that you can call (the ones used by the GUI itself), though these commands have not been fully documented and tested with the scripting functionality, so please use with caution.
https://simtk.org/api_docs/opensim/gui_docs/org/opensim/console/gui.html
Available Example Scripts
...