Brendan Dawes
The Art of Form and Code

Modifying TouchDesigner Table DATs

This drove me a little crazy for a good hour, so I thought I'd make a note of this for myself and maybe for others.

I had a table DAT in TouchDesigner, being fed from a csv file. All was good. At some later point I needed to change the cell of a certain row to act as a flag, using Python. According to the docs this is simply a case of targeting the cell in the table like this:

table = op('mytable')
table[0,1] = 'flagged'

This should put the word 'flagged' in the first row, second column of the table. Yet when I tried it, I got an error saying the table was not editable. No matter what I did I couldn't seem to change that or any other cell.

After some more reading of the TouchDesigner docs, I eventually found out that tables that are populated by a file — like mine was — are not editable, unless they are locked. So I manually locked it and tried my code again — this time it worked as expected.

Yet for various reasons, I sometimes needed this table unlocked, like when I needed to randomize the order or load new data. Luckily controlling the lock state of an operator such as a table is trivial:

table = op('mytable')
# lock table
table.lock = 1
# or to unlock
table.lock = 0

Using this technique I could lock the table, make my changes, then unlock whenever I needed to. Note, unlocking a file fed table will remove any changes that have been made as it will repopulate the table from the file.