Introduction
- 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.
- Interactive mode (from inside the GUI of SimLab Composer)
Scripting is supported in the Ultimate edition of SimLab Composer
Command line without scripting
Command line Python Scripts
SimLabComposer.exe -py “File.py”
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 Java Scripts interactively in different ways:
- Select a script from the scripting library, drag it, and drop it on the 3D area
- Select a script from the library, then from the Script menu, click Run
- Select the node/geometry to Isolate from the 3D area or the Object Tree, then click OK.
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.
<!-- 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">"-i"</span> ); <span style="color: #888888">//you can pass this arg if you want to import another file that isn'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">"-o"</span> );
</pre></div>
<!-- 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">"C:\Scripts\script.js"</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">"c:\\temp\\input.obj"</span>;
<span style="color: #008800; font-weight: bold">var</span> outputImage = <span style="color: #dd2200; background-color: #fff0f0">"c:\\temp\\output.png"</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:
- Select a script from the scripting library, drag it, and drop it on the 3D area
- Select a script from the library, then from the Script menu, click Run
- Click Run in the script dialog, for the Import file dialog to appear.
Using UI Elements In Interactive Mode
- 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">"Enter First and Last Frames:"</span>,
[{type: runtime.ui.DATA_TYPE_VALUE, label:<span style="color: #dd2200; background-color: #fff0f0">"FirstFrame:"</span> },
{type: runtime.ui.DATA_TYPE_VALUE, label:<span style="color: #dd2200; background-color: #fff0f0">"LastFrame:"</span> }], <span style="color: #008800; font-weight: bold">true</span>);
</pre></div>