This tutorial covers Data Operators (DATs) in TouchDesigner - operators designed to hold and manipulate text data including strings, scripts, and XML.

What Are DATs?

DATs (Data Operators) are one of the five operator families in TouchDesigner. They handle text-based data in two primary formats:

  1. Text DATs - Multiple lines of text (scripts, strings, XML)
  2. Table DATs - Cells organized in rows and columns

Working with Text DATs

Creating a Text DAT

  1. Open the OP Create dialog
  2. Navigate to the DAT family
  3. Add a Text DAT to your network

To interact with a Text DAT directly, click the viewer active flag and type your content (e.g., “Hello World”).

Connecting Text DAT to Text TOP

A common workflow is displaying Text DAT contents in a Text TOP:

  1. Add a Text TOP to your network
  2. Clear the default text parameter value
  3. Drag your Text DAT onto the DAT parameter of the Text TOP

The Text DAT contents now appear in the Text TOP. If text doesn’t fit, enable the word wrap parameter.

Working with Table DATs

Creating and Editing Tables

  1. Add a Table DAT from the OP Create dialog
  2. Make the viewer active to edit cells directly
  3. Right-click on rows to add new rows above or below

Specifying Table Dimensions

You can create tables with exact dimensions by setting the rows and columns parameters. For example, create a table with 2 rows and 1 column, then populate it with values.

Merging Tables

Use the Merge DAT to combine multiple tables:

  1. Add a Merge DAT to your network
  2. Box-select multiple Table DATs (hold right mouse button)
  3. Drag-connect them to the Merge DAT
  4. Choose merge mode: “Append Rows” or “Append Columns”

Sorting Table Data

The Sort DAT organizes table contents:

  1. Right-click on a DAT output and add a Sort DAT
  2. Specify which column to sort by (using column index)
  3. Choose sort order (ascending/descending)
  4. Select sort type (numeric or alphabetical)

Execute DATs: Event-Driven Python

Execute DATs run Python code based on events in your TouchDesigner network. This is a powerful way to create interactive behaviors.

CHOP Execute Example

  1. Add an LFO CHOP (set to pulse mode)
  2. Connect it to a Count CHOP (increments value over time)
  3. Right-click the Count output and add a CHOP Execute DAT

Configuring Execute Flags

The CHOP Execute DAT has several flags that determine when code runs:

  • Off to On - When value goes from 0 to 1
  • On to Off - When value goes from 1 to 0
  • Value Change - Every time the value changes (most common)

Writing Python in Execute DATs

Enable the Value Change flag and edit the onValueChange method:

# Print value to text port
print(val)

View output in Dialogs > Textport and DATs - useful for debugging Python code.

Updating UI Components

Instead of printing to the text port, update a Text COMP parameter:

op('text3').par.text = val

This updates the text parameter every time the value changes. Hovering over the parameter shows where it was set (e.g., “set in chopexecute1 on line 23”).

Key Takeaways

  • Text DATs hold multi-line text content
  • Table DATs organize data in rows and columns
  • Merge DAT combines multiple tables
  • Sort DAT orders table contents
  • Execute DATs trigger Python code from network events
  • Use the Textport for debugging Python output
  • Parameter tooltips show the source of programmatic changes

This tutorial covers just the basics - DATs offer many more capabilities for data manipulation in TouchDesigner.

本教程介绍TouchDesigner中的数据操作符(DATs) - 专门用于保存和处理文本数据的操作符,包括字符串、脚本和XML。

什么是DATs?

DATs(数据操作符)是TouchDesigner五大操作符家族之一。它们以两种主要格式处理基于文本的数据:

  1. 文本DAT - 多行文本(脚本、字符串、XML)
  2. 表格DAT - 按行和列组织的单元格

使用文本DATs

创建文本DAT

  1. 打开OP创建对话框
  2. 导航到DAT家族
  3. 将文本DAT添加到网络中

要直接与文本DAT交互,点击viewer active标志并输入内容(例如”Hello World”)。

将文本DAT连接到文本TOP

一个常见的工作流程是在文本TOP中显示文本DAT的内容:

  1. 在网络中添加一个文本TOP
  2. 清除默认的文本参数值
  3. 将文本DAT拖放到文本TOP的DAT参数上

文本DAT的内容现在显示在文本TOP中。如果文本不适合,启用word wrap参数。

使用表格DATs

创建和编辑表格

  1. 从OP创建对话框添加表格DAT
  2. 激活viewer active以直接编辑单元格
  3. 右键点击行以在上方或下方添加新行

指定表格尺寸

您可以通过设置行和列参数来创建具有精确尺寸的表格。例如,创建一个2行1列的表格,然后填充数值。

合并表格

使用Merge DAT来合并多个表格:

  1. 在网络中添加Merge DAT
  2. 框选多个表格DAT(按住鼠标右键)
  3. 将它们拖动连接到Merge DAT
  4. 选择合并模式:“追加行”或”追加列”

排序表格数据

Sort DAT用于组织表格内容:

  1. 右键点击DAT输出并添加Sort DAT
  2. 指定要排序的列(使用列索引)
  3. 选择排序顺序(升序/降序)
  4. 选择排序类型(数字或字母)

Execute DATs:事件驱动的Python

Execute DATs根据TouchDesigner网络中的事件运行Python代码。这是创建交互行为的强大方式。

CHOP Execute示例

  1. 添加一个LFO CHOP(设置为脉冲模式)
  2. 将其连接到Count CHOP(随时间递增数值)
  3. 右键点击Count输出并添加CHOP Execute DAT

配置Execute标志

CHOP Execute DAT有几个标志决定代码何时运行:

  • Off to On - 当值从0变为1时
  • On to Off - 当值从1变为0时
  • Value Change - 每次值变化时(最常用)

在Execute DATs中编写Python

启用Value Change标志并编辑onValueChange方法:

# 将值打印到文本端口
print(val)

Dialogs > Textport and DATs中查看输出 - 这对调试Python代码很有用。

更新UI组件

不是打印到文本端口,而是更新Text COMP参数:

op('text3').par.text = val

这会在每次值变化时更新文本参数。将鼠标悬停在参数上会显示它是在哪里设置的(例如”set in chopexecute1 on line 23”)。

关键要点

  • 文本DATs保存多行文本内容
  • 表格DATs按行和列组织数据
  • Merge DAT合并多个表格
  • Sort DAT对表格内容排序
  • Execute DATs从网络事件触发Python代码
  • 使用Textport调试Python输出
  • 参数工具提示显示程序化更改的来源

本教程仅涵盖基础知识 - DATs在TouchDesigner中提供了更多数据处理功能。