Introduction to Python

From TouchDesigner 099 Wiki
(Redirected from Python)

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

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: docs.python.org/tutorial. Here is an excellent way to start coding instantly: codeacademy.com. And here is a cheat-sheet of python methods: http://overapi.com/python.

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

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

Implementation

On startup, TouchDesigner runs TouchInit.py 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

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