Tdu Module

The tdu module is a generic utility module containing all miscellaneous functions that don't refer specifically to TouchDesigner data structures. tdu is imported by default when the application launches.


fileTypesdict (Read Only):

A dictionary of all supported file types, organized by category.

# example of various file types accepted by Movie File In TOP
# other file types

Note: Acceptable file types can be both uppercase and lowercase, so if suffix is a suffix string, you need to force it to lowercase by using suffix.lower():

for suffix.lower() in tdu.fileTypes['movie']:

Matrixtdu.Matrix (Read Only):

The Matrix definition class.

Positiontdu.Position (Read Only):

The Position definition class.

Vectortdu.Vector (Read Only):

The Vector definition class.

Quaterniontdu.Quaternion (Read Only):

The Quaternion definition class.

Colortdu.Color (Read Only):

The Color definition class.

Dependencytdu.Dependency (Read Only):

The Dependency definition class.

PathInfotdu.PathInfo (Read Only):

The PathInfo object takes a file path and has a few utility properties to provide additional information. It is derived from str, so will work as a Python string, but can be differentiated from a regular string by using isinstance(tdu.PathInfo).

Utility properties include:

path: filepath string
ext: string after and including "."
fileType: the TD filetype (from tdu.fileTypes)
absPath: the absolute path to filepath
dir: the containing directory of filepath
exists: exists in file-system
isDir: is a directory in the file-system
isFile: is a file in the file-system

ArcBalltdu.ArcBall (Read Only):

The ArcBall definition class.



Return a random value in the range [0.0, 1.0) given the input seed value. That is, it will never return 1.0, but it may return 0.0. For a given seed, it will always return the same random number. The seed does not need to be a number. If the seed is not numeric, it resolves it to its string representation to produce a unique value. In the case of OPs for example, its string representation is a constant path. Thus one can produce a unique random value for each OP which remains the same for that OP each time you reload TouchDesigner.

tdu.rand(me) # return a specific random number based on path
tdu.rand(5) # return a specific random number
tdu.rand(absTime.frame) # return a different number every frame

clamp(inputVal, min, max)val:

Returns the input value clamped between min and max values. Arguments can be any type that can be compared (float, int, str, etc).

remap(inputVal, fromMin, fromMax, toMin, toMax)float:

Returns the input value remapped from the first range to the second.

tdu.remap(0.5, 0, 1,  -180, 180)  #remap slider value to angle range


Returns the beginning portion of the string occurring before any digits. The search begins after the last slash if any are present.

  • str - The string to extract the base name from.
tdu.base('arm123') # returns 'arm'
tdu.base('arm123/leg456') # returns 'leg'

Note this method will work on any string, but when given a specific operator, its more efficient to use its local base member:

n = op('arm123/leg456')
b = n.base #returns 'leg'

digits(str)int or None:

Returns the numeric value of the last consecutive group of digits in the string, or None if not found. The search begins after the last slash if any are present. The digits do not nessearily need to be at the end of the string.

tdu.digits('arm123') # returns 123
tdu.digits('arm123/leg456') # returns 456
tdu.digits('arm123/leg') # returns None, searching is only done after the last /
tdu.digits('arm123/456leg') # returns 456

Note this method will work on any string, but when given a specific operator, its more efficient to use its local digits member:

n = op('arm123/leg456')
d = n.digits # returns 456


Returns a version of the string suitable for an operator name. Converts illegal characters to underscores.

tdu.legalName('a#bc def') # returns 'a_bc_def'


Return a list of the expanded items.

tdu.expand('A[1-3] B[xyz]') # return ['A1', 'A2', 'A3', 'Bx', 'By', 'Bz']


Expand the file path, using project.paths, the current folder, and any other relevant information.

tdu.expandPath('movies:/test.bmp') # looks at project.paths for 'movies' entry.

collapsePath(path, asExpression=False)str:

Collapse the file path, using project.paths, the current folder, and any other relevant information.

tdu.collapsePath('C:/downloads/test.bmp') # looks at project.paths for any entries matching the path, and removes current folder from prefix.
  • path - The path to be shortened.
  • asExpression - (Keyword, Optional) If True, result can be used as an expression, including App Class members and quoted strings.

split(string, eval=False)list:

Return a list from a space separated string, allowing quote delimiters.

  • string - Any Python object, as it will be evaluated as str(string). Parameters will work.
  • eval - (Keyword, Optional) If True convert any valid Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None.
split('1 2.3 None fred "one \'2\'" "[1,2]"') #yields ['1', '2.3', 'None', 'fred', "one '2'", '[1, 2]']
split('1 2.3 None fred "one \'2\'" "[1,2]"', True) #yields [1, 2.3, None, 'fred', "one '2'", [1, 2]]

match(pattern, inputList, caseSensitive=True)list:

Return a subset of inputList, in which each element matches the pattern. Wildcards are supported.

tdu.match('foo*', ['foo', 'bar']) # return ['foo']
tdu.match('ba?', ['foo', 'bar']) # return ['bar']


Returns a set of values based on the input calibration data. This Method is not necessary anymore due to the inclusion of openCV in TouchDesigner. Refer to OpenCV Documentation

TouchDesigner Build: