txversion Executable Previous

Appendix B, Toxik Executables
Python Scripting



Python scripting in Toxik is implemented by extending the Python language (http://www.python.org). Since Toxik is written in the C++ programming language, this means that we wrote some libraries that allow us to bind our C++ functions to equivalent Python functions. The result is the Toxik Python API. With Python and the Toxik Python API installed, you can write scripts to automatically perform certain repetitive managerial tasks and creative work on a project, such as creating compositions, adding nodes to it, importing material, publishing, rendering, and so on. Access to the API, is simply done with a statement in the script. Once imported, functions from selected modules, like database.openDb(), can be used.

Because a project is not shareable, it must not be opened by more than one Toxik application at a time. It is important that you know that a Python script using Toxik functions is indeed a Toxik application, in the same way that the interactive application is. So when running a script, make sure that the project is not opened by another application.

Note: Since there is no way to prevent someone from opening the same project using a different instance of Toxik, it is your responsibility to make sure it does not happen.

Viewing Information and Error Messages Top

Some scripts may output some information or error messages during execution. All output explicitly printed by the script writer goes to the script console, which is a pop-up window with one line of text. New text overrides any previous text. When the scripts complete, the window closes. If there were errors during the script execution, another window is displayed, containing information or the stack trace that was generated when the error occurred. Information and error messages are displayed by default, but you can turn them off in the user preferences.

To turn off feedback while running scripts:
  1. In the taskbar, click your user name to open the User Preferences window.

  2. Select the Embedded Scripting tab.

    Show full-size image

  3. Deselect any of the following:

Embedded Scripting Top

Since it not possible to run an external python script while a project is opened by an application, embedded scripting lets you circumvent this by letting you run Python scripts within Toxik.

Some operations, like Archive and Restore are implemented as Python scripts. So when you use either operation, the embedded interpreter runs Python code seamlessly with the C++ code. No conflict arises since the embedded script is part of the same process as the interactive application.

Some operations, like Render in background, are also implemented as Python scripts, but this particular script does not run embedded. When you start a render operation, the application creates an archive of the composition and then launches an external process (which is the equivalent of running a distinct application) to run the render script. This is possible because the render script does not need to open the project file.

Using Custom Scripts Top

Thanks to embedded scripting, you can also write and execute your own custom scripts within the application. The scripts can be located anywhere in the file system. Toxik recognizes the files ending in .py as Python scripts and identifies them with a thumbnail that represents the Python logo.

Show full-size image

To run a custom Python:
  1. In the Import Browser (Ctrl + I), navigate to your custom script.

  2. Right-click your script and do any of the following:

    Show full-size image

Previous