TouchDesigner

myCheatSheet

COMP Class

op('base1').inputCOMPs # list of components connected to the input

op('base1').outputCOMPs # list of components connected to the output

Create operator inside a COMP

op('base').create(lookupCHOP, 'my_lookup')

# To delete use the .destroy() method of the OP Class

Scroll to Top

Connecting Operators

op('text').outputConnectors[0].connect(op('transform').inputConnectors[0])

Scroll to Top

DATs

Select even/odd cells of a Table DAT with Select DAT

Row Select Condition:

me.inputRow % 2 == 0 for even

me.inputRow % 2 == 1 for odd

Col Select Condition:

me.inputCol % 2 == 0 for even

me.inputCol % 2 == 1 for odd

Scroll to Top

Delay Scripts

Delay one line of code:

delay = "print('message')"

run(delay, delayFrames = 3 * me.time.rate) for 3 seconds delay

Delay two or more lines of code (make a Text DAT and call it):

op('delay_script').run(delayFrames = 60) ➝ for 60 frames delay

Scroll to Top

Local Variables / Modules / Storage

Local Variables

  • Create a Base COMP, and rename it with “local”
  • Inside the “local”, create a Null (DAT op), and also rename it with “variables”
  • Create a Table (DAT op), and connect with “variables”

me.var('your_var_name')

Modules

  • Create a Base (COMP op), and rename it with “local”
  • Inside the “local”, create a Base (COMP op), and also rename it with “modules”.
  • Inside the “modules”, create a Text DAT and you can also change the name if you want. (It’ll make the modules more clear.)

me.mod.TEXT_OP_Name.VARIABLE_Name


Storage

  • Use “store()” function to store data.
  • Use “fetch()” function to get data.
  • Use “unstore()” function to remove data.

Scripts :

me.parent().store(‘the_target_data’)  # Store the data

me.parent().fetch(‘the_target_data’)  # Get the data

me.parent().unstore(‘the_target_data’) # Unstore the data.

me.parent().unstore(‘*’)  # Unstore everything.



Scroll to Top

OP Class

Unique ID of an operator → int

op('text').id

Name → str

op('text').name

Digits → str

op('text').digits # last consecutive group of digits in the name, or None if not found. The digits can be in the middle of the name if there are none at the end of the name

Base → str

op('text').base

Par → td.Par

op('text').par.font

Scroll to Top

PYTHON|ACCESSING-PARAMETER-BY-NAME

op('constant1').par[ 'value0' ] = 2

for i in range(10) : op( 'constant1' ).par[ f'value{i}' ] = 2

setattr( op('constant1').par , 'value0' , 2 )

for i in range(10) : setattr( op('constant1').par , f'value{i}' , 2 )

parameter = op('constant1').par[ 'value0' ]

parameter = getattr( op('constant1').par , 'value0' )

hasparameter = hasattr( op('constant1').par , 'value0' )

Scroll to Top

PYTHON|STRING-FORMATTING

# .format() method

'Hello, {} !'.format(name)

# f-Strings

f'Hello, {name} !'

Scroll to Top

PYTHON|STRINGS

tdu.base('arm123')'arm'

tdu.base('leg456arm') leg456arm

tdu.digits('arm123') 123

tdu.digits('arm123/leg456') 456

tdu.digits('arm123/leg') None, searching is only done after the last /

tdu.digits('arm123/456leg') 456

tdu.digits('arm123/456leg22')) returns 22

tdu.split('Of course, Club 22.9 38', eval=False) ['Of', 'course,', 'Club', '22.9', '38']

tdu.split('Of course, Club 22.9 38', eval=True) ['Of', 'course,', 'Club', 22.9, 38]

tdu.expandPath('malamas') '/Users/vassilismalamas/Desktop/malamas'

tdu.collapsePath('/Users/vassilismalamas/Desktop/malamas'))'malamas'

Select substring from the beginning of the string till you find a specific character (left to right)

string = 'Vassilis, Malamas, Touch, 29'

partitioned_string = string.partition(',')

result = partitioned_string[0] ➝ 'Vassilis'

Select substring from the end of the string till you find a specific character (right to left)

string = 'Vassilis, Malamas, Touch, 29'

rev_string = string[::-1]

partitioned_rev_string = rev_string.partition(',')

select_rev_string = partitioned_rev_string[0]

result = select_rev_string[::-1] ➝ ' 29'

Scroll to Top

Par Class

op('geo1').par.tx.val   # the constant value
op('geo1').par.tx.eval()   # the evaluated parameter
op('geo1').par.tx.val = 5
op('geo1').par.tx = 5  #equivalent to above, more concise form

op('geo1').par.tx.expr = 'absTime.frame'  #set to match current frame

p.enableExpr = "me.par.X.menuIndex == 5"

p.bindExpr = "op('geo1').par.tx"

op('myOperator').par.Custompar.name = 'Translate'

readOnlybool :

Get or set the parameter's read only status. When True the parameter cannot be modified through the UI, only scripting.

enablebool :

Get or set the parameter's enable state. Can only be set on Custom Parameters.

---

eval()value:

Evaluate a parameter. This value may be derived by the parameter's constant value, expression, or export, dependent on its mode.

a = op('geo1').par.tx.eval()

pulse(value, frames=nframes, seconds=nseconds)None:

For example, the following are equivalent in a parameter:

  • (float)me.par.tx
  • me.par.tx.eval()
  • me.par.tx

The following are also equivalent:

  • me.par.tx.eval() + 1
  • me.par.tx + 1

As are the following:

  • me.par.tx.val = 3
  • me.par.tx = 3

Scroll to Top

Project Class

project.folder returns a string with the disk path of the folder of the .toe file: '/Users/vassilismalamas/Desktop'

my_fps = project.cookRate returns a float with the target fps: 60.0

project.cookRate = 30set the cook rate to 30 FPS

realtime_flag = project.realTime returns True or False

project.realTime = False turn off real time playback

Scroll to Top

Python References

target_path = "../container{}".format(int(op('constant').par.value0))

op(target_path).par.Param = 100

Scroll to Top

Random Values

Random float number in range [0.0, 1.0) → with same seed, same value

number.tdu.rand(me) ➝ specific random number based on path

tdu.rand(5) ➝ specific random number

tdu.rand(absTime.frame) ➝ a different number every frame

Random Integer

import random

randNum = random.randint(1,20)

or

mod.random.randint(1,20)

Scroll to Top

TEMP

LFO Sin

tdu.remap(math.sin(absTime.seconds*0.1),-1,1,0,5)

Round to two digits

round(me.par.Value0.eval(),2)

Scroll to Top

UI-TRICKS

  • Press F9 on a Panel COMP and a new window will pop-up of the network of this Panel COMP
Scroll to Top

tdu Module

tdu.clamp(op('lfo')['chan1'] ,-0.5, 0.5) clamps values

tdu.remap(op('lfo')['chan1'] ,-1, 1,  -180, 180) remaps values

Scroll to Top