Writing your own Scripts

Navigation:  Toolboxes > Scripting Toolbox > Scripting in Octave/Matlab >

Writing your own Scripts

Previous pageReturn to chapter overviewNext page

Example

We will show you how to write your own scripts using a simple example. We assume that you have installed a scripting folder and its location is:

 

'C:\Users\yourusername\Documents\20simscripting'

 

of course you can use own location. We will copy a 20-sim model to the scripting folder and write a script that will open this model in 20-sim and run a simulation.

 

1.Copy the example model FastManipulator.emx tot the Octave\tutorials folder. E.g copy:

'C:\Program Files (x86)\20-sim 4.6\Models\Examples\Drivetrains\FastManipulator.emx'

to

'C:\Users\yourusername\Documents\20simscripting\Octave\tutorials\FastManipulator.emx'

2.Open a text editor (e.g. notepad) and enter the following lines:

run('../library/xxsim/xxsimAddToPath.m');

xxsimConnect();

xxsimOpenModel( 'FastManipulator.emx' );

xxsimProcessModel();

xxsimRun(); 

xxsimDisconnect();

3.Save the text file as:

'C:\Users\yourusername\Documents\20simscripting\Octave\tutorials\MyScript.m'

4.Open 20-sim.
5.Open Octave (or Matlab).
6.In Octave/Matlab, change the local working directory. Type in the command line:

cd 'C:\Users\yourusername\Documents\20simscripting\Octave\tutorials'

7.In Octave/Matlab, run your own script. Type in the command line:

MyScript

Now you will see the model being loaded in 20-sim and a simulation being run.

Writing your own scripts

In the tutorial folder there are more scripts. Use these as a template for writing you own scripts and follow the guidelines below:

Location

Create your own subfolder inside your scripting working folder. This allows you to update the 20-sim scripting files when new versions of 20-sim are released.

Functions

You can find help on scripting functions in the 20-sim Editor by selecting Help - Octave Scripting API.