Logo vun Td Python Extension

Td Python Extension

Organisatioun
TouchDesigner
td-python-extension

Python extensions — extension classes, ext0object, parameter callbacks, lifecycle, state/persistence, scriptTOP/numpy. Use when building Python-driven baseCOMPs.

Iwwersiicht

EditeurTouchDesigner
RepositoryTDMCPSkills
Skill-Nummtd-python-extension
Stären
42
Forks
1
Matgeliwwert Fichieren
2
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 2 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    Vum TouchDesigner op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Td Python Extension an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/TouchDesigner/TDMCPSkills/tree/main/skills/td-python-extension
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/TouchDesigner/TDMCPSkills.git /tmp/TDMCPSkills
mkdir -p .claude/skills
cp -r /tmp/TDMCPSkills/skills/td-python-extension .claude/skills/td-python-extension
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Td Python Extension an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Td Python Extension automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Td Python Extension net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Python Extensions

Patterns for Python extension components in TouchDesigner. Complements td-comp-architecture (structure/custom pars) and td-dat-family (callback mechanics). See reference.md for API signatures and examples.md for complete patterns.

Create an extension — one pass

The fixed choreography. Author the class (step 3) and verify (step 7); the rest is invariant. Mirrors what TD's own Component Editor produces.

  1. baseCOMP base_<x> — name it now; binding and docked refs snapshot at creation.
  2. textDAT <Name> inside — DAT = module = class, one identifier (e.g. SimpleExt).
  3. set_dat_content the Skeleton (below) → code/py/<comp-path>/<Name>.py.
  4. language=python — set it explicitly; set_dat_content doesn't (see Sync to File).
  5. ext0object = op('./<Name>').module.<Name>(me) + ext0promote=True — leave ext0name empty (promoted under the class name). ext0 always exists → no sequence management.
  6. pulse reinitextensions.
  7. Gate — not done until proven: get_errors clean AND a promoted member called from outside returns a value (op('base_<x>').Hello()). Print it.

Inspect an existing one: get_operator_info(path, include_extensions=true) — class names, promoted signatures, clone sources.

Naming & promotion

  • DAT == module == class — one identifier; Ext/EXT suffix optional. me.mod("<Name>").<Name>(me) is an equivalent shorthand for the step-5 binding.
  • Capitalized members = promoted (external via comp.Member); lowercase/underscore = internal.
  • Promotion exposes Capitalized methods; use @property (or TDF.createProperty) for promoted data.
  • Store self.ownerComp in __init__.

Skeleton

Bare MCP create(textDAT) gives you an empty DAT — author this skeleton (it mirrors TD's Component Editor template). Going through the Component Editor harvests it for you.

python
from TDStoreTools import StorageManager
import TDFunctions as TDF

class CounterExt:
	"""CounterExt description"""
	def __init__(self, ownerComp):
		self.ownerComp = ownerComp

		# Dependable property — cooks dependents when it changes
		TDF.createProperty(self, 'MyProperty', value=0, dependable=True, readOnly=False)

		self.a = 0   # internal attribute
		self.B = 1   # promoted attribute (Capitalized)

		# Persistent across saves AND re-initialization:
		storedItems = [
			{'name': 'StoredProperty', 'default': None, 'readOnly': False,
			 'property': True, 'dependable': True},
		]
		# self.stored = StorageManager(self, ownerComp, storedItems)

	def myFunction(self, v):        # internal
		debug(v)

	def PromotedFunction(self, v):  # external (Capitalized)
		debug(v)

	# def onInitTD(self):    # after all extensions attached — cross-ext deps
	# 	debug("onInitTD called")
	# def onDestroyTD(self): # cleanup; use instead of __del__
	# 	debug("onDestroyTD called")

Sync to File

The editor (and create) make the extension DAT embedded, not on disk. Getting it into the code-on-disk workflow is a follow-on step — one set_dat_content call writes the file and sets file/syncfile (it does NOT set language — set that yourself, step 4):

  • Path: code/py/<comp>/<subcomp>/<Name>.py — see td-dat-family for the canonical flow
  • After syncing, edit on disk; the DAT auto-re-inits on external edit (no reinitextensions).
  • Re-init wipes plain state. It runs __init__, so self.a-style attributes reset every edit. State that must survive re-init (and saves) belongs in StorageManager stored items (the self.stored block above), not plain attributes.

Parameter Callback Routing

Extension reacts to custom parameter changes via parameterexecuteDAT:

  • op = .., pars = *, builtin = False
  • Generic routing loops through par.owner.extensions calling onParValueChange / onParPulse
  • Without this DAT, the extension is deaf to parameter changes

Lifecycle

  • __init__(ownerComp) — creation/reinit, store refs, declare slots as None
  • onInitTD() — after all extensions attached, safe to access other exts
  • onDestroyTD() — cleanup (use instead of __del__)

Use onInitTD when depending on other components' extensions being ready.

State & Persistence

  • State lives on self — never on module globals. Module globals re-execute on reinit and lose state
  • TDF.createProperty (from import TDFunctions as TDF) for reactive/dependable state — list/panel callbacks reading ext.PropertyName auto-recook on change. Plain self.x = ... does NOT trigger downstream recooks. e.g. TDF.createProperty(self, 'MyProperty', value=0, dependable=True, readOnly=False)
  • StorageManager (from from TDStoreTools import StorageManager) for persistence across saves:
python
storedItems = [
    {'name': 'History', 'default': [], 'readOnly': False,
     'property': True, 'dependable': True},
]
self.stored = StorageManager(self, ownerComp, storedItems)

scriptTOP + numpy

copyNumpyArray() must run inside onCook — calling it elsewhere raises tdError.

Stage-and-cook: extension stages self._pixels, calls script_top.cook(force=True), scriptTOP onCook calls back into extension which runs copyNumpyArray.

Safe Operator Resolution

Custom parameters referencing operators (TOP, CHOP, etc.) may be empty or invalid. Always resolve safely — check for None and validate before using.

Internal Layout

Extension DAT and parameterexecuteDAT at X=-200 (left of origin). Main operator chain flows right from X=0. Output null at chain end.

DAT Module Imports

  • Same COMP: mod.datName or from datName import X (module-level only)
  • Cross COMP: op('comp').mod.datName — the only reliable pattern
  • Syncing a DAT to a file does NOT strip TD globals — a file-synced DAT is still a DAT, so op, me, project, debug, etc. are available (extensions sync to disk fine). The "no globals" caveat applies only to a plain .py imported as a module outside any DAT namespace.

Pitfalls

  • ext0object as expression — must be constant-mode string, not expression
  • ext0promote only promotes methods — not attributes; use @property for data
  • copyNumpyArray outside onCook — stage data on extension, call from onCook only
  • Language not set on extension DAT — always language=python
  • No parameterexecuteDAT — extension won't react to custom parameter changes
  • Module-level heavy imports — import torch/numpy in a setup method, not at module top
  • Name collision on create — TD silently appends numbers; verify .name matches requested
  • HTTP/urllib in main thread — blocks cook loop; use webClientDAT or run() with delayFrames
  • Forgetting reinitextensions (in-DAT edits only) — code edited inside the DAT doesn't reload until pulsed. A file-synced DAT auto-re-inits on external disk edit. Either way, re-init wipes plain attributes — persist anything that must survive via StorageManager (see Sync to File)
  • findChildren(type=textDAT) without maxDepth=1 — crawls into annotateCOMPs and other utility COMPs, triggering compilation of their internal DATs as Python. Always use maxDepth=1 when loading sibling modules
  • Assuming op reference pars are valid — always check for None before using

Matgeliwwert Fichieren

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill Td Python Extension?

Python extensions — extension classes, ext0object, parameter callbacks, lifecycle, state/persistence, scriptTOP/numpy. Use when building Python-driven baseCOMPs.

Firwat Td Python Extension op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Td Python Extension besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Td Python Extension an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/TouchDesigner/TDMCPSkills/tree/main/skills/td-python-extension an. TypingMind liest d'Datei SKILL.md, bündelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Td Python Extension benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Td Python Extension benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Td Python Extension domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Td Python Extension gratis?

De Skill gëtt vum TouchDesigner op GitHub publizéiert. Kuckt am Repository no de Lizenzbedéngungen. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇