Python Script

Tools  -  Write Python scripts inside Smode

PythonScriptTool PythonScriptTool PythonScriptTool PythonScriptTool

This tool lets you run Python scripts in Smode.

Learn how to use Python scripts in Smode by reading the Python scripting section of the documentation.


Code execution

The parameter Launch Mode defines when the script is executed. By default it is set to “Manual”.

The options are:

  • Manual : when the Execute trigger is pressed

  • At Preload : at script preload, for instance when the project is loading

  • At Activation : at script activation and reactivation

  • At Parameter Change : when a parameter of the script changes

  • At Every Update : every frame

  • At Deactivation : at script deactivation

  • At Unload : at script unload, for instance when the project is closing

CTRL + ENTER: Compile your script (the console will display every Syntax Errors if you have some)

CTRL + SPACE: Run your script ( + Compilation if needed)

Here is your first script:

text = "Smode"
print(f"Hello {text} World")

What Python does (and what it cannot do) ?

The script runs inside the rendering service. If the code take too long to execute, the framerate will be impacted. That’s why the time.sleep() function need to be used carefully.

It doesn’t have access to UI function (example: Learn feature is not available).

It can’t draw on the rendering.


Variables:

  • Launch Mode: Defines when the current script is executed
  • Execute: Manually execute the script

Python

    Oil.createObject("PythonScriptTool")