Python Scripting

Wrap supports Python for project script and parameter expressions.

Tip

Currently Python 3.8.3 is using.

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, seven built-in functions are supported:

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

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

  • nodeParamValue(nodeName: str, paramName: str) returns the value of a parameter of a node.

  • commonDir() returns value of $COMMON_DIR.

  • galleryDir() returns value of $GALLERY_DIR.

  • projectDir() returns value of $PROJECT_DIR.

  • projectName() returns value of $PROJECT_NAME.

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

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

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 + Enter

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.