Introduction to Python

From TouchDesigner Documentation
Jump to: navigation, search

TouchDesigner allows scripting in both Python and Tscript. The current Python version supported is 3.7.

If you know some python already, see the Introduction to Python Tutorial.

The "Python" link on the left of this page is the entry point to the hierarchy of Python classes of TouchDesigner.

An online tutorial for python in general can be found at: Here is an excellent way to start coding instantly: And here is a cheat-sheet of python methods:

The TouchDesigner Python classes are organized below, and detailed in the Python Reference Category.

Examples of Python in TouchDesigner can be opened via Help -> Python Examples.

Commonly-used Python expressions are here: Python Tips.

Inputting Scripts[edit]

Python scripts can be entered in the textport, DATs, and operator parameters.

For a description of how this is done, refer to Introduction to Python Tutorial.

The family of execute DATs that handle events using python callbacks include: CHOP Execute DAT, Panel Execute DAT, DAT Execute DAT, Execute DAT, OP Execute DAT, Parameter Execute DAT

OPs that react to other circumstances using python callbacks include: OSC In DAT, Serial DAT, Art-Net DAT, UDP In DAT, Timer CHOP, Multi Touch In DAT, Render Pick DAT, Keyboard In DAT, MIDI In DAT, OP Find DAT


On startup, TouchDesigner runs which initializes enumerations and DAT importing functions as well as:

  • import sys
  • import re
  • import math
  • from td import *

See sys, math and re.

The td Module is the main module containing all application related classes and objects. It does not need to be explicitly included.

Its main classes can be organized as follows:

In addition to the above, the td Module also contains a specific class type for each specific operator. For example, the Wave CHOP is represented by the waveCHOP Class. The naming convention for the classes is to remove all spaces and make the node type name all lowercase. The node family is always all uppercase. For example the Render Pass TOP's class name will be renderpassTOP.

Specialized Operators[edit]

Many of the operator classes contain methods and members specific to their operator. They are:

An Operator Family that manipulates text strings: multi-line text or tables. Multi-line text is often a command Script, but can be any multi-line text. Tables are rows and columns of cells, each containing a text string.