Ajasra
8/14/2019 - 10:38 AM

TouchDesigner useful

Seconds (bound to Time Line)

me.time.seconds

Seconds (absolute Time – constantly incrementing)

me.time.absSeconds (Legacy method)
absTime.seconds

Frame (bound to Time Line)

me.time.frame

Frame (absolute Frame count – constantly incrementing)

me.time.absFrame (Legacy Method)
absTime.frame

Scripts

op( 'container1' ).openViewer()

Copy

Example 1
op( 'to' ).copy( op( 'from' ) )

Example 2
to = op( 'to' )
from = op( 'from' )

to.copy( from )

Run a .bat file from Python in TouchDesigner

from subprocess import Popen

file = "E:\\GitHub\\Beneath\\tools\\robo_copy\\batTest.bat"

Popen( [ file ] )

Execute a string

target_par = 'invert'
target_op = 'level1'
val = 0

# build your script as a string
command = "op( '" + target_op + "' ).par." + target_par + " = " + str( val )

# print to debug and make sure it's what you want to be
print( command )

# execute the command
exec( command )

TouchDesigner User Interface Scripts

Open an Explorer Window

op( 'text1' ).text = ui.chooseFile( fileTypes = tdu.fileTypes[ 'image' ], title = 'Select an image' )

Change the Background Color Syntax – ui.colors[‘worksheet.bg’] = ( r , g , b ) Example We can make our background bright green.

ui.colors[ 'worksheet.bg' ] = ( 0.0 , 1.0 , 0.0 )

Format a Group of Ops

# create an empty list for all ops
null_ops = []

# create a list of names
null_types = [ 
    null_tops, 
    null_sops,
    null_dats,
    null_mats,
    null_chops 
]

# create lists of all op types
null_tops = parent().findChildren( type = nullTOP )
null_sops = parent().findChildren( type = nullSOP )
null_dats = parent().findChildren( type = nullDAT )
null_mats = parent().findChildren( type = nullMAT )
null_chops = parent().findChildren( type = nullCHOP )

# extened empty list with the contents of all op types
for type in null_types:
    null_ops.extend( type )

# turn off the display of all ops, set them to black
for item in null_ops:
    op( item ).viewer = False
    op( item ).color = 0 , 0 , 0

# debugging line - check the contents of the null_ops list
# print( null_ops )

OP CLASS

'valid' op( 'text2' ).valid
'id'    op( 'text2' ).id
'name'  op( 'text2' ).name
'path'  op( 'text2' ).path
'digits'    op( 'text2' ).digits
'base'  op( 'text2' ).base
'passive'   op( 'text2' ).passive
'time'  op( 'text2' ).time
'activeViewer'  op( 'text2' ).activeViewer
'allowCooking'  op( 'text2' ).allowCooking
'bypass'    op( 'text2' ).bypass
'cloneImmune'   op( 'text2' ).cloneImmune
'current'   op( 'text2' ).current
'display'   op( 'text2' ).display
'expose'    op( 'text2' ).expose
'lock'  op( 'text2' ).lock
'selected'  op( 'text2' ).selected
'render'    op( 'text2' ).render
'viewer'    op( 'text2' ).viewer
'nodeHeight'    op( 'text2' ).nodeHeight
'nodeWidth' op( 'text2' ).nodeWidth
'nodeX' op( 'text2' ).nodeX
'nodeY' op( 'text2' ).nodeY
'nodeCenterX'   op( 'text2' ).nodeCenterX
'nodeCenterY'   op( 'text2' ).nodeCenterY
'inputs'    op( 'text2' ).inputs
'outputs'   op( 'text2' ).outputs
'type'  op( 'text2' ).type
'subType'   op( 'text2' ).subType
'label' op( 'text2' ).label
'family'    op( 'text2' ).family
'isFilter'  op( 'text2' ).isFilter
'minInputs' op( 'text2' ).minInputs
'maxInputs' op( 'text2' ).maxInputs
'isMultiInputs' op( 'text2' ).isMultiInputs
'visibleLevel'  op( 'text2' ).visibleLevel
'isBase'    op( 'text2' ).isBase
'isCHOP'    op( 'text2' ).isCHOP
'isCOMP'    op( 'text2' ).isCOMP
'isDAT' op( 'text2' ).isDAT
'isMAT' op( 'text2' ).isMAT
'isObject'  op( 'text2' ).isObject
'isPanel'   op( 'text2' ).isPanel
'isSOP' op( 'text2' ).isSOP
'isTOP' op( 'text2' ).isTOP

example

# create a new variable called new_op
# this is also a copy of the operator out 1
new_op = parent().copy( op( 'moviefilein1' ) )

# since we've defind our new op with the variable
# name new_op we can continue to use this name
# our next step will be to give it a name
new_op.name = 'moviefilein_new_op'

# finally we're going to change the location of
# our new operator. In this example we want it
# created at a location in relation to our original
# operator. We start by finding the original operator's
# y position, and then subtract 200
new_op.nodeY = op( 'moviefilein1' ).nodeY - 100

get value of base parameters

ipar.ExtPython.Pyreqs
# ipar.<baseGlobalName>.<parameterName>

get full path to file

tdu.expandPath(ipar.ExtPython.Pyreqs)

write to file

with open(str(win_file), "w+") as win_script:
    win_script.write(formatted_win_txt)