td_extension_add
Attach a Python class to a TouchDesigner COMP as an extension in one call, handling creation, parameter setup, and error reporting.
Instructions
Attach a Python class to a COMP as an extension, in one call.
Reach for this instead of td_exec whenever a component needs methods or
state of its own. Done by hand it is five steps — create the COMP, create
the DAT, write the text, set three parameters on the Extensions page,
re-initialise — and the last one fails silently: measured on 2025.32460, a
wrong Extension Object expression or a class that raises in __init__
leaves the COMP reporting no error, no warning, and extensionsReady True,
with the real message only in the textport. This tool reads the result back
off the COMP and hands you that message.
Aim it either at path (an existing COMP) or at parent plus name (a
baseCOMP to create) — not both. code must define class <class_name>,
conventionally taking ownerComp and capitalising anything meant to be
called from outside: with promote on, capitalised members are callable
straight on the COMP, and every member is reachable as
op(...).ext.<name>.<member> regardless.
The class name doubles as the name of the textDAT holding the code, which
is what the generated Extension Object expression points at
(op('./Name').module.Name(me)). extension_name renames the extension
for ext lookups without touching the class. index picks which
extension slot to write; the wiki says a COMP has four, the sequence took
six here. A created COMP is given a free spot in the parent network
unless position names one — [x, y] in network units, the left and
bottom edges of the tile; it is ignored when aiming at a COMP that
already exists.
The code is parsed on this host before anything is sent, so a typo costs
no round trip. That check is not a guarantee TouchDesigner accepts it:
this host's Python may be newer than TouchDesigner's embedded 3.11, so
3.12+ syntax passes here and fails there — which is caught, but only by
the read-back above. Pass the same owner you claimed the area with, or
your own claim refuses this write.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| name | No | ||
| path | No | ||
| index | No | ||
| owner | No | ||
| parent | No | ||
| promote | No | ||
| position | No | ||
| class_name | Yes | ||
| extension_name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |