LoginSignup
8
8

More than 3 years have passed since last update.

PythonでOP/COMPを制御する

Last updated at Posted at 2019-10-12

TouchDesignerはノードベースのプログラミング言語ですが、Pythonでも書けます。
『どこに書くか?』についてはsatoruhigaさんが、Pythonの基本的な書き方はいろんなひとが書いているので今回は『TouchDesignerの機能を具体的にPythonで制御するには?』について書きたいと思います。

TouchDesignerで主に扱う3つのClass

TouchDesignerをPythonで扱う場合、主に4つのクラスを扱います。
COMP Class, OP Class, Par ClassConnector Classです。
COMP ClassはBase COMPなどのCOMPを扱うときのクラス、OP ClassはTOPやSOPなどを扱うクラス、そしてOPやCOMPが持つ各種の値、例えばtx, ty, tzやbuttonのw(width), h(height)などがPar Classとなっています。
Connector ClassはOPやCOMPが持つコネクタの部分(OP同士をつなげるワイヤを繋ぐところです)のクラスです。

また、細かく言えばOP Classは各OPごとにOP Classを継承して作られていますが、今回は個別のメソッドには触れず、全体に共通した処理を紹介していきます。
個別のを見たければCHOP Class, TOP Class, SOP Class, MAT Class, DAT Classで確認できます。

Python上での変数名の確認方法

マウスカーソルを知りたいパラメータの名前の上にロールオーバーすれば名称が表示されます。
"Width"のPython上の変数名は"w"のようです。
pythonmember.png

よく書くやついくつか

よく書く処理を挙げておきます。チートシート替わりにどうぞ。

Constantの値を変更する

直接値の読み書きができます。

op('circle1').par.radiusx.val = 0.5

expressionのパスを変更する

パスを文字列として書き込みます。

op('circle1').par.radiusx.expr = 'absTime.seconds'

モードを変更する

Expressionモードにするには、

op('circle1').par.radiusx.mode = ParMode.EXPRESSION

Constantモードにするには、

op('circle1').par.radiusx.mode = ParMode.CONSTANT

Connector Classの例1. OP同士をつなぐ

コネクタが一個しかないものは、

op('circle1').onputConnectors[0].connect(op('level1'))

コネクタが複数あるのものは、

op('circle1').onputConnectors[0].connect(op('comp1').inputConnectors[0])

ちなみにconnectメソッドはインプットコネクタからも叩けます。

op('level1').inputConnectors[0].connect(op('circle1').outputConnectors[0])

COMP同士をつなぐ

基本OPのコネクタと一緒で、名称がinputCOMPConnector/outputCOMPConnectorになってるだけです。

op('button1').outputCOMPConnectors[0].connect(op('container1').inputConnectors[0])

Inputの数を数える

len(op('circle1').inputConnectors)
len(op('button1').inputCOMPConnectors)

コネクションを解除する

op('circle1').inputConnectors[0].disconnect()
op('button1').inputCOMPConnectors[0].disconnect()

OPやCOMPの位置を移動する

op('circle1').nodeY = op('circle1').nodex + 10
op('button1').nodeY = op('button1').nodeY + 10
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8