Contents

This website contains the Python module API documentation for the available Python scripting functions.

Introduction

20-sim scripting allows you to run tasks in 20-sim automatically using specialized scripting functions. With these functions you can open models, run simulations, change parameters, store results and much more.

_images/python-20sim-scripting.png

The usage of 20-sim scripting from Python allows you to run sequences of scripts, run numerical routines on the outcomes and much more!

Getting Started

Using the Python console

You can open an interactive Python (IPython) console from the Windows start menu. You can find it in the 20-sim start menu folder.

_images/ipython.png

The first step to communicate with 20-sim from Python is to import the Controllab package and to create an instance of the XXSim() class:

>>> import controllab
>>> xxsim = controllab.XXSim()

The next step is to connect to 20-sim. When 20-sim is already running, Python will connect to the running instance. When no 20-sim instance is running, Python will try to start 20-sim.

>>> xxsim.connect()
True

Now, it is possible to call all available 20-sim scripting functions. See controllab package for the available functions.

A complete example that opens a model, sets a parameter and simulates it:

import controllab
import os
xxsim = controllab.XXSim()
xxsim.connect()
mymodel = os.path.join(xxsim.path(), 'Models', 'Examples', '1D Mechanics', 'Crank Rod Mechanism with Sledge.emx')
xxsim.open_model(mymodel)
xxsim.process_model()
xxsim.run()
xxsim.set_parameters('Load.m', 1.0)
xxsim.run()

Function list