Python Scripting

Wrap supports Python for project script and parameter expressions.

Tip

Currently Python 3.12.9 is used.

Python Parameter Expression

A new scripting button is located next to a majority of node parameters indicating that the parameter is scriptable.

../../_images/PythonScriptingButton.jpg

If the parameter script is computed with errors, the scripting button turns red. If you hold the mouse over the scripting button, an error message will be displayed.

When clicking on the scripting button a Python Expression Editor dialog shows up.

../../_images/PythonExpressionEditor.png

A single line of code is treated as a Python expression and should return a value.

1 + 2 * 3

Multi-line code is treated as the body of a function and should end with the return statement.

fileName = "Model.obj"
dir = "C:/Models/"
return dir + fileName

Currently, the following built-in functions are supported:

  • frame() returns the current frame number on the timeline.

  • frame_range() returns the tuple of the timeline’s start and end numbers.

  • node_param_value(node_name: str, param_name: str) returns the value of a parameter of a node.

  • common_dir() returns value of $COMMON_DIR.

  • gallery_dir() returns value of $GALLERY_DIR.

  • project_dir() returns value of $PROJECT_DIR.

  • project_name() returns value of $PROJECT_NAME.

  • project_path() returns the absolute file path of project, or empty string if it wasn’t saved.

  • interpret_path(path_str: str) returns a string with all path variables replaced, or unchanged string if none contained.

  • wrap.cuda.devices() returns a list of available CUDA devices as dictionaries with ordinal, name, uuid and pci_bus_id fields. Returns an empty list if no devices are available. Requires the extended Python API.

Note

Since 2026, we moved to PEP 8 names style. Old camel case aliases are still avilable: frameRange, nodeParamValue, commonDir, galleryDir, projectDir, projectName, projectPath, interpretPath.

Python Project Script

Each Wrap project has a project script that can store Python code that is accessible from every parameter expression. In the project script you can store common functions or classes that can be repeatedly used in different places.

Go to File >> Edit Project Script or click CTRL + I to open the Project Script Editor dialog.

../../_images/PythonProjectScriptEditor.png

Ctrl + Return

to accept project script changes and exit

F5

to validate and dry-run written code

ESC

to cancel changes and exit

Alt + 1

to toggle output panel visibility

Tip

By default each run of project script clears a global Python context. Clearing prevents reappearing of removed variables and functions. Nevertheless you can change clearing policy in Preferences >> Code Editor >> Auto-Reset Project Script Context. If unset, it adds a Clear Context button (with shortcut Ctrl + 0) for clearing context manually.