| name | td-python |
| description | Write Python scripts for TouchDesigner — parameter expressions, DAT callbacks, Script OPs, Extensions, and module patterns. Use when creating Python expressions, DAT scripts, Execute DATs, Script CHOPs/TOPs/SOPs/DATs, component extensions, or any TouchDesigner Python automation, interaction, or data scripting. |
TouchDesigner Python Scripting
Write Python optimized for TouchDesigner's scripting environment.
Quick Start
There are four main contexts where Python runs in TouchDesigner:
absTime.frame
me.par.tx
op('noise1')['chan1']
round(op('slider1').par.value0.eval(), 2)
r = op('/project1/geo1')
r.par.tx = 5
print(dir(r))
def onCook(scriptOp):
scriptOp.clear()
scriptOp.appendRow(['name', 'value'])
def onValueChange(par, prev):
debug(par, prev)
Critical Rules
- Use
debug() not print() — debug() adds source location; essential for tracking down errors
- Use
.eval() when passing par to functions — round(op('x').par.tx) fails; round(op('x').par.tx.eval()) works
- Never access TD objects at module root — put them in functions or the module will recompile on every change
me = the operator running this script — works in expressions and DATs
op() paths are relative by default — / prefix makes them absolute from root
The Core Objects (Always Available, No Import Needed)
me
op('name')
op('/project1/geo1')
op.MyGlobalShortcut
parent()
parent(2)
parent.MyShortcut
absTime.frame
absTime.seconds
ext.MyExtension
Common Patterns
See examples/PATTERNS.md for ready-to-use templates:
- Parameter expressions
- Callback DATs (parameter, CHOP, panel, execute)
- Script OPs (Script CHOP, TOP, SOP, DAT)
- Extensions
- DATs as modules
Response Format
When providing Python code, always include:
- Python code with comments
- Context — where this code goes (expression field, DAT name, callback function)
- TouchDesigner setup — what operators to create, how to wire them, which parameters to configure
Writing Process
- Identify the context (expression / callback / script OP / extension / module)
- Write the minimal working script
- Add error handling and
debug() calls
- Note any required operator connections or parameter setup
Additional Resources