Skip to main content

Introduction

SimLab Composer allows using Python, and Java Scripts to automate processes, both scripts automation are supported in two modes:

  1. Command line (for batch processing for a large number of files). This includes command line without scripting using -ie command, and with scripting using Python, and Java scripts. 
  2. Interactive mode (from inside the GUI of SimLab Composer)

image.png

Scripting is supported in the Ultimate edition of SimLab Composer

Command line without scripting

Open command line window, by typing "cmd" in Start. Go to the directory where SimLab Composer was installed, the default installation directory is "C:\Program Files\SimLab\SimLab Composer 10" to go there type cd C:\Program Files\SimLab\SimLab Composer 10 

image.png

Now to run import/export functions in SimLab Composer, type Sim.. then start clicking Tab button, until SimLabComposer.exe appears. 

image.png

Type in the code -ie <import_file> <export_file>

With actual files locations the below line will convert RubikCube.obj 3D models into RubikCube.skp in the indicated folders. Don't forget " "

-ie "C:\Users\simlab\Desktop\Delete\RubikCube.obj" "C:\Users\simlab\Desktop\Delete\RubikCube.skp"

Check this article for more about command line based method, also for commands on Mac. 

Command line Python Scripts

Python scripts can be run from the command line using the following command

SimLabComposer.exe -py “File.py”
So if the user named the firsta script as example.py, and saved it in folder C:\Scripts, The user should use the following command

SimLabComposer.exe -py “C:\Scripts\example.py”

Passing arguments to Python Scripts

Passing arguments to a script makes it dynamic, and reusable without the need to change its code. 

	
scene =Scene()
runtime =RunTime()
scene.reset()
fileName= runtime.args.getAsString("-path")
scene.importFile(fileName)

Interactive Scripting - Running Python script interactively

The user can run Python Scripts interactively in different ways:

  1. Select a script from the scripting library, drag it, and drop it on the 3D area 

    image.png

  2.  Select a script from the library, then from the Script menu, click Run 

    image.png

My first Python script / Python Scripts using GUI input

The following script, gets location to save rendered image in, using a GUI dialog. Renders the current scene, saves the resulting image in the selected location, and finally displays a dialog indicating that rendering is done. 

from simlabpy import *

scene = Scene()
runtime = RunTime()
render_path = runtime.ui.getSaveFileName("Exported rendered image location:", "", "*.jpg;;*.png")
scene.render(render_path)
runtime.ui.alert("Rendered image was created.")

For a list of supported Python scripting commands visit this page

Automation/Debugging Java Scripts

Command line Java Scripts

Java scripts can be run from the command line by using the following command

<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">SimLabComposer.exe -js <span style="color: #a61717; background-color: #e3d2d2">“</span>File.js<span style="color: #a61717; background-color: #e3d2d2">”</span>
</pre></div>

So if the user named the first script as example.js, and saved it in folder C:\Scripts, The user should use the following command

<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">SimLabComposer.exe -js <span style="color: #a61717; background-color: #e3d2d2">“</span>C:<span style="color: #a61717; background-color: #e3d2d2">\</span>Scripts<span style="color: #a61717; background-color: #e3d2d2">\</span>example.js<span style="color: #a61717; background-color: #e3d2d2">”</span>
</pre></div>

Passing arguments to Java Scripts

Looking at the My First Java Script example below, the user defined on top of the java script the name of the file to be imported and the output image file. 

For this script to work as expected, it is the users responsibility to name and place the input file as "c:\\temp\\input.obj" and to make sure the output file "c:\\temp\\output.png" is copied to another place before re-running the java script, so it is not overwritten. 

Another option for the user is to use the input file name and the output image name as arguments as shown in the following scripting

To do this, instead of defining the variables on top of the script as done before, we can use the runtime.args functionality, as shown in the following example:

<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">var</span> inputFile = runtime.args.getAsString( <span style="color: #dd2200; background-color: #fff0f0">&quot;-i&quot;</span> ); <span style="color: #888888">//you can pass this arg if you want to import another file that isn&#39;t included in your current scene</span>
<span style="color: #008800; font-weight: bold">var</span> outputImage = runtime.args.getAsString( <span style="color: #dd2200; background-color: #fff0f0">&quot;-o&quot;</span> );
</pre></div>
Other than changing the first two lines, the rest of the script is just the same.

To use the argument based script as before the user should use the following command:

<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">SimLabComposer.exe -js <span style="color: #dd2200; background-color: #fff0f0">&quot;C:\Scripts\script.js&quot;</span> -i <span style="color: #a61717; background-color: #e3d2d2">“</span>c:<span style="color: #a61717; background-color: #e3d2d2">\\</span>temp<span style="color: #a61717; background-color: #e3d2d2">\\</span>input.obj<span style="color: #a61717; background-color: #e3d2d2">”</span> -o <span style="color: #a61717; background-color: #e3d2d2">“</span>c:<span style="color: #a61717; background-color: #e3d2d2">\\</span>temp<span style="color: #a61717; background-color: #e3d2d2">\\</span>output.png<span style="color: #a61717; background-color: #e3d2d2">”</span>
</pre></div>

This allows the user to control the import file and output image on the command line.

runtime.args supports the following argument types:

  • String
  • Number
  • Color
  • Vector 3
  • String Array
  • Number Array
  • Color Array
  • Vector 3 Array

My first Java script

The following script, imports a file, sets camera in a good position, and renders an image and saves it.

<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">var</span> inputFile   = <span style="color: #dd2200; background-color: #fff0f0">&quot;c:\\temp\\input.obj&quot;</span>;
<span style="color: #008800; font-weight: bold">var</span> outputImage = <span style="color: #dd2200; background-color: #fff0f0">&quot;c:\\temp\\output.png&quot;</span>;

scene.reset(); <span style="color: #888888">// First we clean the scene</span>

<span style="color: #008800; font-weight: bold">var</span> importedScene = scene.importFile(inputFile); <span style="color: #888888">// We import the input file</span>
<span style="color: #008800; font-weight: bold">var</span> bBox = importedScene.computeBoundingBox(); <span style="color: #888888">// Get the bouding box of the scene</span>
<span style="color: #008800; font-weight: bold">var</span> displacementFromWorldCenter = <span style="color: #008800; font-weight: bold">new</span> Vector3(-bBox.center.x, -bBox.center.y, -bBox.center.z);

importedScene.transform.translateInPlace(displacementFromWorldCenter);  <span style="color: #888888">// Move the model to the world center</span>

<span style="color: #008800; font-weight: bold">var</span> newCamera= scene.createCamera();  <span style="color: #888888">//Create new Camera</span>

newCamera.fov = <span style="color: #0000DD; font-weight: bold">30</span>;
newCamera.position.set(<span style="color: #0000DD; font-weight: bold">1.5</span>*(bBox.max.x - bBox.min.x),<span style="color: #0000DD; font-weight: bold">1.5</span>*(bBox.max.y - bBox.min.y), <span style="color: #0000DD; font-weight: bold">3</span>*(bBox.max.z - bBox.min.z)); <span style="color: #888888">//Set psotion of the camera</span>
newCamera.up.set(<span style="color: #0000DD; font-weight: bold">0</span>,<span style="color: #0000DD; font-weight: bold">0</span>,<span style="color: #0000DD; font-weight: bold">1</span>);
newCamera.targetPosition.set(<span style="color: #0000DD; font-weight: bold">0</span>,<span style="color: #0000DD; font-weight: bold">0</span>,<span style="color: #0000DD; font-weight: bold">0</span>); <span style="color: #888888">//Set targer of the camera</span>

runtime.setView(newCamera); <span style="color: #888888">// Use the new Cemera</span>

scene.render(outputImage, <span style="color: #0000DD; font-weight: bold">600</span>, <span style="color: #0000DD; font-weight: bold">400</span>);
</pre></div>

Interactive Scripting - Running Java script interactively

The user can run Java Scripts interactively in different ways:

  1. Select a script from the scripting library, drag it, and drop it on the 3D area 

    image.png

  2. Select a script from the library, then from the Script menu, click Run 

    image.png

  3. Click Run in the script dialog, for the Import file dialog to appear. 

    image.png

Using UI Elements In Interactive Mode

Interactive Java scripts allows the user to create a dialog from the script to collect needed data, supported types include:

  • DATA_TYPE_VALUE: value number 
  • DATA_TYPE_STRING: string  
  • DATA_TYPE_BOOL: boolean 
  • DATA_TYPE_VECTOR3: vecotr 3
  • DATA_TYPE_RAY3: ray 3 (the user can enter the value or pick from the scene) 
  • DATA_TYPE_NODE: scene node (the user can enter name, or select from the scene)
  • DATA_TYPE_NODE_ARRAY: array of scene nodes
  • DATA_TYPE_COLOR: color
  • DATA_TYPE_FILENAME_OPEN: open file name 
  • DATA_TYPE_FILENAME_SAVE: save file name

The user can simply create GUI to collect users data by using the following command:

<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">var</span> data = runtime.ui.getData(<span style="color: #dd2200; background-color: #fff0f0">&quot;Enter First and Last Frames:&quot;</span>,
[{type: runtime.ui.DATA_TYPE_VALUE, label:<span style="color: #dd2200; background-color: #fff0f0">&quot;FirstFrame:&quot;</span> },
{type: runtime.ui.DATA_TYPE_VALUE, label:<span style="color: #dd2200; background-color: #fff0f0">&quot;LastFrame:&quot;</span> }], <span style="color: #008800; font-weight: bold">true</span>); 
</pre></div>
This script will simply create a frame and allow the user to input values of First and Last frames

Values set by the user will be defined in data[0] and data[1].