Call Functions from Another Operator in TouchDesigner — Tip in TouchDesigner#8

Partical Weng
Partical.grt
Published in
2 min readJan 22, 2022

--

In TouchDesigner, we always use op() to get a single operator to read its value or change it.

What if I wrote a function in a Text (DAT) and want to call it from other operators, could I use op() to get the target function?

-

-

No

You cannot use op() to get the function inside.

-

The solution is → mod()

mod() will use the target operator like a module.

According the official document:

The MOD class provides access to Module On Demand object, which allows DATs to be dynamically imported as modules. It can be accessed with the mod object, found in the automatically imported td module. Alternatively, one can use the regular python statement: import. Use of the import statement is limited to modules in the search path, where as the mod format allows complete statements in one line, which is more useful for entering expressions. Also note that DAT modules cannot be organized into packages as regular file system based python modules can be.

Okay, that’s so much.

Let’s just explain it with a example will be really easy to understand

mod(DAT Name).FUNCTION NAME()

Create a Text (DAT) “text1” and write a function to print “Happy Programing” inside.

And create another Text (DAT) to just write down a script using mod().

When I Run Script “text2”, you can see it printed out in the Textport dialog.

--

--

Partical Weng
Partical.grt

A person love new things and extremely futurism.