Difference between revisions of "Td Module"

From Derivative
Jump to navigation Jump to search
m
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
 
{{lowercase}}
 
{{lowercase}}
{{TDClassSummary|label=td|summary=The td module is the main TouchDesigner module, and contains all of the application related classes, objects, and utilities. All td module members and methods are imported when the application launches and are automatically available in scripts, expressions, and the textport.<br><br>For classes and objects not related directly to TouchDesigner, see the [[Tdu Module]]}}
+
{{TDClassSummary|label=td|summary=The td module contains all TouchDesigner related Python classes and utilities. All td module members and methods are imported when the application launches and are automatically available in scripts, expressions, and the textport.<br><br>For additional helpful Python classes and utilities not directly related to TouchDesigner, see the [[Tdu Module]]}}
 
<section begin=HELPBODY />
 
<section begin=HELPBODY />
 
{{ClassMemberSection|empty=
 
{{ClassMemberSection|empty=
Line 45: Line 45:
 
     |type=licenses
 
     |type=licenses
 
     |set=0
 
     |set=0
     |text=Reference to the currently installed licences.
+
     |text=Reference to the currently installed [[Licenses Class|licences]].
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
Line 215: Line 215:
 
     |class=td
 
     |class=td
 
     |name=isMainThread
 
     |name=isMainThread
     |call=isMainTread()
+
     |call=isMainThread()
 
     |returns=bool
 
     |returns=bool
 
     |text=Is True when called from the main application editing thread. Any calls that access operators, etc., must be called from the main thread.
 
     |text=Is True when called from the main application editing thread. Any calls that access operators, etc., must be called from the main thread.
Line 227: Line 227:
 
}}}}
 
}}}}
 
<section end=HELPBODY />
 
<section end=HELPBODY />
== Python Class Hierarchy ==
+
== Python Classes and Modules ==
The following TouchDesigner object classes are available in the td module as well: <br>
+
More detailed information about the contents of td module:
{{:Python Class Hierarchy}}
+
{{:Python Classes and Modules}}
  
 +
{{history}}
 
{{#invoke:Category|list|Python Reference}}
 
{{#invoke:Category|list|Python Reference}}

Latest revision as of 21:43, 6 May 2021


The td module contains all TouchDesigner related Python classes and utilities. All td module members and methods are imported when the application launches and are automatically available in scripts, expressions, and the textport.

For additional helpful Python classes and utilities not directly related to TouchDesigner, see the Tdu Module


Members[edit]

meOP (Read Only):

Reference to the current operator that is being executed or evaluated. This can be used in parameter expressions, or DAT scripts.

absTimeabsTime (Read Only):

Reference to the AbsTime object.

appapp (Read Only):

Reference to the application installation.

extext (Read Only):

Reference to the extension searching object. See extensions for more information.

familiesdict (Read Only):

A dictionary containing a list of operator types for each operator family.

for a in families['SOP']:
	# do something with a

licenseslicenses (Read Only):

Reference to the currently installed licences.

modmod (Read Only):

Reference to the Module On Demand object.

monitorsmonitors (Read Only):

Reference to the group of available monitors.

opOP (Read Only):

The Shortcut object, for accessing operators through paths or shortcuts.

Note: a version of this method that searches relative to a specific operator is also in OP Class.

op(pattern1, pattern2...) OP or None

Returns the first OP whose path matches the given pattern, relative to the current OP, or None if nothing is found. Multiple patterns may be specified which are all added to the search. Numeric OP ids may also be used.

  • pattern - Can be string following the Pattern Matching rules, specifying which OP to return, or an integer, which must be an OP Id. Multiple patterns can be given, the first matching OP will be returned.
b = op('project1')
b = op('foot*', 'hand*')
b = op(154)

op.shortcut OP

An operator specified with by a shortcut. If no operator exists an exception is raised. These shortcuts are global, and must be unique. That is, cutting and pasting an operator with a Global OP Shortcut specified will lead to a name conflict. One shortcut must be renamed in that case. Furthermore, only components can be given Global OP Shortcuts.

  • shortcut - Corresponds to the Global OP Shortcut parameter specified in the target operator.
b = op.Videoplayer # or alternatively op.Videoplayer, as its not relative to this operator.

To list all Global OP Shortcuts:

for x in op:
	print(x)

parentOP (Read Only):

The Parent Shortcut object, for accessing parent components through indices or shortcuts.

Note: a version of this method that searches from a specific operator is also in OP Class.

parent(n) OP or None

The nth parent of the current operator. If n not specified, returns the parent. If n = 2, returns the parent of the parent, etc. If no parent exists at that level, None is returned.

  • n - (Optional) n is the number of levels up to climb. When n = 1 it will return the operator's parent.
p = parent(2) #grandfather

parent.shortcut OP

A parent component specified with a shortcut. If no parent exists an exception is raised.

  • shortcut - Corresponds to the Parent Shortcut parameter specified in the target parent.
   n = parent.Videoplayer

See also Parent Shortcut for more examples.

iopOP (Read Only):

The Internal Operator Shortcut object, for accessing internal shortcuts. Note: a version of this method that searches from a specific operator is also in OP Class.

iparOP (Read Only):

The Internal Operator Parameter Shortcut object, for accessing internal shortcuts. Note: a version of this method that searches from a specific operator is also in OP Class.

projectproject (Read Only):

Reference to the project session.

rootOP (Read Only):

Reference to the topmost root operator.

runsruns (Read Only):

Reference to the runs object, which contains delayed executions.

sysinfosysinfo (Read Only):

Reference to the system information.

uiui (Read Only):

Reference to the ui options.

Methods[edit]

passive(OP)OP:

Returns a passive version of the operator. Passive OPs do not cook before their members are accessed.

run(script, arg1, arg2..., endFrame=False, fromOP=None, asParameter=False, group=None, delayFrames=0, delayMilliSeconds=0, delayRef=me)Run:

Run the script specified as a string in the script parameter, returning a Run object which can be used to optionally modify its execution.

  • script - A string that is the script code to execute.
  • arg - (Optional) One or more arguments to be passed into the script when it executes. They are accessible in the script using a tuple named args.
  • endFrame - (Keyword, Optional) If True, the execution will be delayed until the end of the current frame.
  • fromOP - (Keyword, Optional) Specifies an optional operator from which the execution will be run relative to.
  • asParameter - (Keyword, Optional) When fromOP used, run relative to a parameter of fromOP.
  • group - (Keyword, Optional) Can be used to specify a string label for the group of Run objects this belongs to. This label can then be used with the td.runs object to modify its execution.
  • delayFrames - (Keyword, Optional) The number of frames to wait before executing the script.
  • delayMilliSeconds - (Keyword, Optional) The number of milliseconds to wait before executing the script. This value is rounded to the nearest frame.
  • delayRef - (Keyword, Optional) Specifies an optional operator from which the delay time is derived.

fetchStamp(key, default)value:

Return an object from the global stamped parameters. If the item is not found, the default is returned instead. Parameters can be stamped with the Copy SOP.

  • key - The name of the entry to retrieve.
  • default - If no item is found then the passed value is returned instead.
v = fetchStamp('sides', 3)

var(varName)str:

Find the value for the given variable.

varExists(varName)bool:

Returns true if the variable is defined.

varOwner(varName)OP or None:

Returns the operator that defines the variable, or None if it's not defined.

isMainThread()bool:

Is True when called from the main application editing thread. Any calls that access operators, etc., must be called from the main thread.

clear()None:

Clear the textport of all text.

Python Classes and Modules[edit]

More detailed information about the contents of td module:


The following list of important Python classes and modules is roughly grouped together by subject.

Python Reference has an alphabetical list of all TouchDesigner Python pages on this wiki.

Operator Related Classes[edit]

The following classes are Python interfaces for operators and objects that operators use. Individual operator classes (e.g. TextTOP Class and RampTOP Class) are not listed but do exist in the td module, and links to each can be found here or by clicking on the Python Help button in their parameter dialog. These classes are found in the td module so do not need to be imported.

Helper Classes[edit]

The following helper objects are part of the td module and can thus be accessed anywhere, including expressions, without imports (e.g. absTime.frame).

Standard Python Modules[edit]

The td module also automatically imports a number of helpful standard modules, allowing them to be accessed in expressions through their namespace (e.g. math.cos(math.pi)):

  • collections - container datatypes
  • enum - support for enumerations
  • inspect - inspect live objects
  • math - mathematical functions
  • re - regular expression operations
  • sys - OS specific data and functions
  • traceback - stack utilities
  • warnings - warning control

TouchDesigner Utility Modules and Python Utilities[edit]

The following contain extended Python utilities for use with TouchDesigner.


3rd Party Packages[edit]

The following 3rd party packages are automatically installed with TouchDesigner. They are not in the td module, so must be imported explicitly to be used in scripts. The name in parentheses is the actual package name used (e.g. to use OpenCV, write this at top of script: import cv2). For information on adding or installing other Python modules, see Importing Modules.

  • asn1crypto (asn1crypto) - Parsing and serializing ASN.1 structures
  • Authlib (authlib) - Library to build OAuth and OpenID Connect servers.
  • Certifi (certifi) - Root Certificates for validating the trustworthiness of SSL certificates while verifying the identity of TLS hosts
  • CFFI (cffi) - Interaction with C code
  • Chardet (chardet) - The Universal Character Encoding Detector
  • Cryptography (cryptography) - High level recipes and low level interfaces to common cryptographic algorithms
  • idna (idna) - Support for the Internationalised Domain Names in Applications (IDNA) protocol
  • jsonpath (jsonpath_ng) - JSONPath tools for accessing and altering JSON structures
  • MWParserFromHell (mwparserfromhell) - An easy-to-use and outrageously powerful parser for MediaWiki wikicode
  • NumPy (numpy) - Fundamental package for scientific computing with Python
  • OpenCV (cv2) - Open source computer vision.
  • ply (ply) - Parsing tools for lex and yacc.
  • Requests (requests) - The only Non-GMO HTTP library for Python, safe for human consumption
  • Requests OAuthlib (requests_oauthlib) - Easy-to-use Python interface for building OAuth1 and OAuth2 clients
  • urllib3 (urllib3) - HTTP client
  • PyYAML (yaml) - YAML parser and emitter

Installing Custom Packages and Modules[edit]

You can also install your own Python packages that are not included with TouchDesigner. For instructions, go here.

TouchDesigner Build: