Difference between revisions of "Td Module"

From Derivative
Jump to: navigation, search
m
(Tag: 2018.28070)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
{{TDClassSummary|summary=The td module is the main module containing all application related classes and objects. It is imported by default when the application launches.}}
+
{{TDClassSummary|label=td|summary=The td module is the main module containing all application related classes and objects. It is imported by default when the application launches.}}
 
<section begin=HELPBODY />
 
<section begin=HELPBODY />
 
{{ClassMemberSection|empty=
 
{{ClassMemberSection|empty=
Line 10: Line 10:
 
     |type=OP
 
     |type=OP
 
     |set=0
 
     |set=0
     |text=Reference to the current operator that is being executed or evaluated. This can be used in parameter expressions, or DAT scripts.
+
     |text=Reference to the current [[OP Class|operator]] that is being executed or evaluated. This can be used in parameter expressions, or DAT scripts.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 17: Line 16:
 
     |type=absTime
 
     |type=absTime
 
     |set=0
 
     |set=0
     |text=Reference to the AbsTime object.
+
     |text=Reference to the [[AbsTime Class|AbsTime]] object.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 24: Line 22:
 
     |type=app
 
     |type=app
 
     |set=0
 
     |set=0
     |text=Reference to the application installation.
+
     |text=Reference to the [[App Class|application]] installation.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 31: Line 28:
 
     |type=ext
 
     |type=ext
 
     |set=0
 
     |set=0
     |text=Reference to the extension searching object. See extensions for more information.
+
     |text=Reference to the extension searching object. See [[extensions]] for more information.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 38: Line 34:
 
     |type=dict
 
     |type=dict
 
     |set=0
 
     |set=0
     |text=A dictionary containing a list of operator types for each operator family. Example: for a in families['SOP']:
+
     |text=A dictionary containing a list of [[OP Class|operator]] types for each operator family.  
}}
+
<syntaxhighlight lang=python>
 +
for a in families['SOP']:
 +
# do something with a
 +
</syntaxhighlight>}}
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 52: Line 51:
 
     |type=mod
 
     |type=mod
 
     |set=0
 
     |set=0
     |text=Reference to the Module On Demand object.
+
     |text=Reference to the [[MOD Class|Module On Demand]] object.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 59: Line 57:
 
     |type=monitors
 
     |type=monitors
 
     |set=0
 
     |set=0
     |text=Reference to the group of available monitors.
+
     |text=Reference to the group of available [[Monitors Class|monitors]].}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 66: Line 63:
 
     |type=OP
 
     |type=OP
 
     |set=0
 
     |set=0
     |text=The OPFinder object, for accessing operators through paths or shortcuts.
+
     |text=The [[Global OP Shortcut|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.
+
'''Note:''' a version of this method that searches relative to a specific operator is also in [[OP Class]].
  
<code>op(pattern1, pattern2...) OP or None</code>
+
<code>op(pattern1, pattern2...) [[OP Class|OP]] or None</code>
  
 
Returns the first OP whose path matches the given pattern, relative to the current OP, or None if nothing is found.
 
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.
 
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.
+
*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.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
b = op('project1')
 
b = op('project1')
Line 79: Line 76:
 
b = op(154)
 
b = op(154)
 
</syntaxhighlight>
 
</syntaxhighlight>
<code>op.shortcut OP</code>
+
<code>op.shortcut OP</code>
  
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.
+
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.
 
*shortcut - Corresponds to the Global OP Shortcut parameter specified in the target operator.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
Line 90: Line 87:
 
for x in op:
 
for x in op:
 
print(x)
 
print(x)
</syntaxhighlight>
+
</syntaxhighlight>}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 97: Line 93:
 
     |type=OP
 
     |type=OP
 
     |set=0
 
     |set=0
     |text=The ParentFinder object, for accessing parent components through indices or shortcuts.
+
     |text=The [[Parent Shortcut|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.
+
   
 +
'''Note:''' a version of this method that searches from a specific operator is also in [[OP Class]].
  
<code>parent(n) OP or None</code>
+
<code>parent(n) OP or None</code>
  
 
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.
 
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.
Line 107: Line 104:
 
p = parent(2) #grandfather
 
p = parent(2) #grandfather
 
</syntaxhighlight>
 
</syntaxhighlight>
<code>parent.shortcut OP</code>
+
<code>parent.shortcut OP</code>
  
 
A parent component specified with a shortcut. If no parent exists an exception is raised.
 
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.
+
*shortcut - Corresponds to the [[Parent Shortcut]] parameter specified in the target parent.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
   n = parent.Videoplayer
 
   n = parent.Videoplayer
 
</syntaxhighlight>
 
</syntaxhighlight>
See also Parent Shortcut for more examples.
+
See also Parent Shortcut for more examples.}}
}}
+
{{ClassMember
 +
    |class=td
 +
    |name=iop
 +
    |type=OP
 +
    |set=0
 +
    |text=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]].}}
 +
{{ClassMember
 +
    |class=td
 +
    |name=ipar
 +
    |type=OP
 +
    |set=0
 +
    |text=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]].}}
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 121: Line 133:
 
     |type=project
 
     |type=project
 
     |set=0
 
     |set=0
     |text=Reference to the project session.
+
     |text=Reference to the [[Project Class|project session]].}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 128: Line 139:
 
     |type=OP
 
     |type=OP
 
     |set=0
 
     |set=0
     |text=Reference to the topmost root operator.
+
     |text=Reference to the topmost root [[OP Class|operator]].}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 135: Line 145:
 
     |type=runs
 
     |type=runs
 
     |set=0
 
     |set=0
     |text=Reference to the runs object, which contains delayed executions.
+
     |text=Reference to the [[Runs Class|runs]] object, which contains delayed executions.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 142: Line 151:
 
     |type=sysinfo
 
     |type=sysinfo
 
     |set=0
 
     |set=0
     |text=Reference to the system information.
+
     |text=Reference to the [[SysInfo Class|system information]].}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=td
 
     |class=td
Line 149: Line 157:
 
     |type=ui
 
     |type=ui
 
     |set=0
 
     |set=0
     |text=Reference to the ui options.
+
     |text=Reference to the [[UI Class|ui options]].}}}}
}}}}
 
 
{{ClassMethodSection|empty=
 
{{ClassMethodSection|empty=
 
|Sectionsummary=
 
|Sectionsummary=
Line 159: Line 166:
 
     |call=passive(OP)
 
     |call=passive(OP)
 
     |returns=OP
 
     |returns=OP
     |text=Returns a passive version of the operator. Passive OPs do not cook before their members are accessed.
+
     |text=Returns a passive version of the [[OP Class|operator]]. Passive OPs do not cook before their members are accessed.}}
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=td
 
     |class=td
 
     |name=run
 
     |name=run
     |call=run(script, arg1, arg2..., endFrame=False, fromOP=None, group=None, delayFrames=0, delayMilliSeconds=0, delayRef=me)
+
     |call=run(script, arg1, arg2..., endFrame=False, fromOP=None, asParameter=False, group=None, delayFrames=0, delayMilliSeconds=0, delayRef=me)
 
     |returns=Run
 
     |returns=Run
     |text=Run the script specified as a string in the script parameter, returning a Run object which can be used to optionally modify its execution.
+
     |text=[[Run Class|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.
 
*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.
 
*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.
 
*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.
+
*fromOP - (Keyword, Optional) Specifies an optional [[OP Class|operator]] from which the execution will be run relative to.
*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.
+
*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 [[Runs Class|td.runs]] object to modify its execution.
 
*delayFrames - (Keyword, Optional) The number of frames to wait before executing the script.
 
*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.
 
*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.
+
*delayRef - (Keyword, Optional) Specifies an optional [[OP Class|operator]] from which the delay time is derived.}}
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=td
 
     |class=td
Line 181: Line 187:
 
     |call=fetchStamp(key, default)
 
     |call=fetchStamp(key, default)
 
     |returns=value
 
     |returns=value
     |text=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.
+
     |text=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.
 
*key - The name of the entry to retrieve.
 
*default - If no item is found then the passed value is returned instead.
 
*default - If no item is found then the passed value is returned instead.
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
v = fetchStamp('sides', 3)
 
v = fetchStamp('sides', 3)
</syntaxhighlight>
+
</syntaxhighlight>}}
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=td
 
     |class=td
Line 193: Line 198:
 
     |call=var(varName)
 
     |call=var(varName)
 
     |returns=str
 
     |returns=str
     |text=Find the value for the given variable.
+
     |text=Find the value for the given [[Variables|variable]].}}
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=td
 
     |class=td
Line 200: Line 204:
 
     |call=varExists(varName)
 
     |call=varExists(varName)
 
     |returns=bool
 
     |returns=bool
     |text=Returns true if the variable is defined.
+
     |text=Returns true if the [[Variables|variable]] is defined.}}
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=td
 
     |class=td
Line 207: Line 210:
 
     |call=varOwner(varName)
 
     |call=varOwner(varName)
 
     |returns=OP or None
 
     |returns=OP or None
     |text=Returns the operator that defines the variable, or None if it's not defined.
+
     |text=Returns the [[OP Class|operator]] that defines the [[Variables|variable]], or None if it's not defined.}}
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=td
 
     |class=td

Latest revision as of 14:48, 13 March 2019


The td module is the main module containing all application related classes and objects. It is imported by default when the application launches.


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.

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

TouchDesigner Build:

Any of the procedural data operators. OPs do all the work in TouchDesigner. They "cook" and output data to other OPs, which ultimately result in new images, data and audio being generated. See Node.

A Link.

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.

An Operator Family that reads, creates and modifies 3D polygons, curves, NURBS surfaces, spheres, meatballs and other 3D surface data.

A name for a component that is accessible from any node in a project, which can be declared in a component's Global Operator Shortcut parameter.

A Parent Shortcut is a parameter on a component that contains a name that you can use anywhere inside the component to refer to that component using the syntax parent.Name, for example parent.Effect.width to obtain panel width.

There are four types of shortcuts: Application Shortcuts that are built-in to TouchDesigner's authoring interface, Panel Shortcuts that you create for any custom built panels, Parent Shortcuts for accessing a component from within that component, and Global OP Shortcuts that access a unique component from anywhere in TouchDesigner.