DAT Class

From TouchDesigner Documentation
Revision as of 15:00, 25 September 2017 by Cimpleo (talk | contribs)
Jump to: navigation, search

A DAT describes a reference to a DAT operator.


Members[edit]

exportbool :

Get or set export flag

isDATbool (Read Only):

True if the operator is a DAT.

isTablebool (Read Only):

True if the DAT contains table formatted data.

isTextbool (Read Only):

True if the DAT contains text formatted data. (ie, not table formatted).

localsdict (Read Only):

Local dictionary used during python execution of scripts in this DAT. The dictionary attribute is read only, but not its contents. Its contents may be manipulated directly with scripts, or with an Examine DAT.

modulemodule (Read Only):

Retrieve the contents of the DAT as a module. This allows for functions in the module to be called directly. E.g n.module.function(arg1, arg2)

numColsint (Read Only):

Number of columns in the DAT table.

numRowsint (Read Only):

Number of rows in the DAT table.

textstr :

Get or set contents. Tables are treated as tab delimited columns, newline delimited rows.

Methods[edit]

run(arg1, arg2..., endFrame=False, fromOP=None, group=None, delayFrames=0, delayMilliSeconds=0, delayRef=me)td.Run:

Run the contents of the DAT as a script, returning a Run object which can be used to optionally modify its execution.

  • arg - (Optional) Arguments that will be made available to the script in a local tuple named args.
  • endFrame - (Keyword, Optional) If set to True, the execution will be delayed until the end of the current frame.
  • fromOP - (Keyword, Optional) Specifies an optional operator from which the execution will be run relative to.
  • group - (Keyword, Optional) Can be used to specify a group label string. This label can then be used with the td.runs object to modify its execution.
  • delayFrames - (Keyword, Optional) Can be used to delay the execution a specific amount of frames.
  • delayMilliSeconds - (Keyword, Optional) Can be used to delay the execution a specific amount of milliseconds. This value is rounded to the nearest frame.
  • delayRef - (Keyword, Optional) Specifies an optional operator from which the delay time is derived.

save(filepath, append=False)str:

Saves the content of the DAT to the file system. Returns the file path that it was saved to.

  • filepath - (Optional) The path and filename to save the file to. If this is not given then a default named file will be saved to project.folder
  • append - (Keyword, Optional) If set to True and the format is txt, then the contents are appended to the existing file.
name = n.save() #save in native format with default name
n.save('output.txt') #human readable format without channel names

write(args)str:

Append content to this DAT. Can also be used to implement DAT printing functions.

# grab DAT
n = op('text1')
# append message directly to DAT
n.write('Hello World')
# use print method
print('Hello World', file=n)

Modifying Content[edit]

The following methods can be used to modify the contents of a DAT. This can be done when the DAT is a Text DAT, or Script DAT for example, or a DAT that is Locked.

Modifying Text Content[edit]

When the DAT is not a table, but a block of text, its contents can be simply accessed through its text member.

Modifying a Single Cell of a Table[edit]

To modify a single cell, where inside the [], integers are the row/column numbers starting at 0, and strings are row or columns names:

tab = op('table1')
tab[0,0] = 'corner'
tab[1,'select'] = 'yes'
tab['Monday',1] = 'day1'

Modifying Table Content[edit]

The following methods can be used to modify the contents of a table type DAT containing rows and columns. This can be done when the DAT is a basic Table DAT, or Script DAT. It can also be used to append rows to FIFO-style DATs such as the Serial DAT.

Accessing Table Content[edit]

rows(nameOrIndex1, nameOrIndex2..., caseSensitive=True)list of lists:

Returns a (possibly empty) list of rows (each row being a list of cells). If no arguments are given it returns all rows in the table.

See DAT.rows() for similar usage.

for r in op('table1').rows():
	# do something with row 'r'

appendCol(vals, nameOrIndex, sort=None)int:

Append a column to the end of the table. See appendRow for similar usage.

insertCol(vals, nameOrIndex, sort=None)int:

Insert a column to the beginning of the table or before the specified row name/index. See DAT.appendRow() for similar usage.

row(nameOrIndex1, nameOrIndex2..., caseSensitive=True)list:

Returns a list of cells from the row matching the name/index, or None if nothing is found. See DAT.col() for similar usage.

col(nameOrIndex1, nameOrIndex2..., caseSensitive=True)list:

Returns a list of all the cells in a column, or None if nothing is found.

  • nameOrIndex - If a string it specifies a column name, if it's numeric it specifies a column index. Pattern Matching is supported.
  • caseSensitive - (Optional) Specifies whether or not case sensitivity is used.
r = op('table1').col(3, caseSensitive=False)
r = op('table1').col('June')
r = op('table1').col('A*', 'B*') #returns first column beginning with A or B

clear(keepSize=False, keepFirstRow=False, keepFirstCol=False)None:

Remove all rows and columns from the table.

  • keepSize - (Keyword, Optional) If set to True, size is unchanged, but entries will be set to blank, dependent on other options below.
  • keepFirstRow - (Keyword, Optional) If set to True, the first row of cells are retained.
  • keepFirstCol - (Keyword, Optional) If set to True, the first column of cells are retained.
n.clear() #remove all rows and columns
n.clear(keepSize=True) #set all table cells to blank
n.clear(keepFirstRow=True) #remove all rows, but keep the first
n.clear(keepFirstRow=True, keepFirstCol=True) #keep the first row, first column, and set remaining cells to blank

cols(nameOrIndex1, nameOrIndex2..., caseSensitive=True)list of lists:

Returns a (possibly empty) list of columns (each being a list themselves). See DAT.col for similar usage. If no arguments are given then all columns in the table are returned.

  • nameOrIndex - (Optional) If a string it specifies a column name, if it's numeric it specifies a column index. Pattern Matching is supported.
  • caseSensitive - (Optional) Specifies whether or not case sensitivity is used.
for c in op('table1').cols():
	# do something with each column 'c'

deleteCol(nameOrIndex)None:

Delete a single column at the specified column name or index.

  • nameOrIndex - May be a string for a column name, or numeric index for column index.

cells(rowNameOrIndex, colNameOrIndex, caseSensitive=True)list:

Returns a (possibly empty) list of cells that match the given row/column names or indices. See DAT.cell method for similar usage.

setSize(numrows, numcols)None:

Set the exact size of the table.

  • numrows - The number of rows the table should have.
  • numcols - The number of columns the table should have.

deleteRow(nameOrIndex)None:

Delete a single row at the specified row name or index.

  • nameOrIndex - May be a string for a row name, or numeric index for rowindex.

appendRow(vals, nameOrIndex, sort=None)int:

Append a row to the end of the table, or after the specified row name/index. Returns the integer index of the new row.

  • vals - (Optional) If specified, will fill the row with the given values. It should be a list of items that can be expressed as strings. Each item will be copied to one cell.
  • nameOrIndex - (Optional) If specified will determine where the new row will be appended. If it's a numeric value it represents the numeric index of the row. If it is a string it represents a row label.
  • sort - (Keyword, Optional) If specified will determine the column to keep sorted after the insertion. If it's a numeric value it represents the numeric index of the column. If it is a string it represents a column label.
n.appendRow()
n.appendRow( [1,2,3], 'January' )  #append with values (1,2,3) after the row labelled 'January'
n.appendRow( [1,2,3], 5 )  #append row with values (1,2,3) after the row 5.
n.appendRow( [1,2,3], sort='Month' )  #append row with values (1,2,3) keeping column 'Month' sorted.

cell(rowNameOrIndex, colNameOrIndex, caseSensitive=True)td.Cell or None:

Find a single cell in the table, or None if none are found.

  • rowNameOrIndex/colNameOrIndex - If a string it specifies a row/column name. If it's numeric it specifies a row/column index. Pattern Matching is supported for strings.
  • caseSensitive - (Optional) Specifies whether or not case sensitivity is used.
c = n.cell(5, 'June') #Return a cell under row 5, column 'June'.
c = n.cell('A*', 2) #Find a cell under any row beginning with an A, in column 2.

copy(DAT)None:

Copy the text or table from the specified DAT operator.

  • OP - The DAT operator whose contents should be copied into the DAT.

insertRow(vals, nameOrIndex, sort=None)int:

Insert a row to the beginning of the table or before the specified row name/index. See DAT.appendRow() for similar usage.

TouchDesigner Build:

An Operator Family that manipulates text strings: multi-line text or tables. Multi-line text is often a command Script, but can be any multi-line text. Tables are rows and columns of cells, each containing a text string.

Matching strings using wildcard characters and bracketing. Useful in "Select" parameters to select multiple operators, paths, etc.

Matching strings using wildcard characters and bracketing. Useful in "Select" parameters to select multiple operators, paths, etc.