tdu Module

From TouchDesigner 099 Wiki


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.

Members

fileTypes (Read Only) A dictionary of all supported file types, organized by category. Example: tdu.fileTypes['movie'] and tdu.fileTypes['image'] which are accepted by thew Movie File In TOP, and others like tdu.fileTypes['audio']. 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 example for suffix.lower() in tdu.fileTypes['movie']:.
Matrix (Read Only) The Matrix definition class.
Position (Read Only) The Position definition class.
Vector (Read Only) The Vector definition class.
Dependency (Read Only) The Dependency definition class.
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

BUILD NOTE: Only available in experimental builds 2017.30000+

ArcBall (Read Only) The ArcBall definition class.
op (Read Only) The OPFinder object, for accessing operators through paths or shortcuts.

Example: op('wave1') # sibling operator named wave1.
Example: op.Videoplayer # an operator with Videoplayer specified in its Global OP Shortcut parameter
Note a version of this method that searches relative to a specific operator is also in the OP Class. Please see for further examples.

parent (Read Only) The ParentFinder object, for accessing parent operators through indices or shortcuts.

Example: parent() # operator's parent
Example: parent(2) # operator's parent's parent
Example: parent.Videoplayer # first parent with Videoplayer specified in its Parent Shortcut parameter
Note a version of this method that searches relative to a specific operator is also in the OP Class. Please see for further examples.

Methods

rand(seed)float

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).

BUILD NOTE: Only available in experimental builds 2017.30000+


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

BUILD NOTE: Only available in experimental builds 2017.30000+


base(str)str

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.
   tdu.digits('arm123') # returns 123
   tdu.digits('arm123/leg456') # returns 456
   tdu.digits('arm123/leg') # returns None

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

legalName(str)str

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'

expandPath(path)path

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)path

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. BUILD NOTE: Only available in experimental builds 2017.30000+


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.

BUILD NOTE: Only available in experimental builds 2017.30000+

   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]]

calibrateCamera(values)results

Returns a set of values based on the input calibration data. Still under development.