Difference between revisions of "DAT Class"

From TouchDesigner Documentation
Jump to: navigation, search
(Created page with "{{ClassSummary |class=DAT |text=A DAT describes a reference to a DAT operator. |inherit=OP |parent=DAT }} <section begin=HELPBODY /> For more information...")
 
(DAT Class Auto Create)
Line 1: Line 1:
{{ClassSummary
+
{{lowercase}}
 
+
{{TDClassSummary|summary=A DAT describes a reference to a DAT operator.}}
 +
{{ClassMemberSection|empty=}}
 +
{{ClassMember
 +
    |class=DAT
 +
    |name=export
 +
    |returns=
 +
    |set=0
 +
    |text=Get or set export flag
 +
}}
 +
{{ClassMember
 +
    |class=DAT
 +
    |name=isDAT
 +
    |returns=
 +
    |set=0
 +
    |text=True if the operator is a DAT.
 +
}}
 +
{{ClassMember
 +
    |class=DAT
 +
    |name=isTable
 +
    |returns=
 +
    |set=0
 +
    |text=True if the DAT contains table formatted data.
 +
}}
 +
{{ClassMember
 
     |class=DAT
 
     |class=DAT
     |text=A DAT describes a reference to a [[DAT]] operator.
+
     |name=isText
     |inherit=OP
+
    |returns=
     |parent=DAT
+
     |set=0
 
+
     |text=True if the DAT contains text formatted data. (ie, not table formatted).
 
}}
 
}}
<section begin=HELPBODY />
 
For more information on using DATs in Python, refer to [[Working with DATs in Python]].
 
 
{{ClassMemberSection|empty=}}
 
 
 
{{ClassMember
 
{{ClassMember
 
     |class=DAT
 
     |class=DAT
     |name=export
+
     |name=locals
     |returns=bool
+
     |returns=
     |set=1
+
     |set=0
     |text=Get or set [[Export Flag|export flag]]
+
     |text=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.
 
}}
 
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=DAT
 
     |class=DAT
 
     |name=module
 
     |name=module
     |returns=module
+
     |returns=
 
     |set=0
 
     |set=0
     |text=Retrieve the contents of the DAT as a module. This allows for functions in the module to be called directly.
+
     |text=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)
:<syntaxhighlight lang=python>n.module.function(arg1, arg2)</syntaxhighlight>
 
 
}}
 
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=DAT
 
     |class=DAT
 
     |name=numCols
 
     |name=numCols
     |returns=int
+
     |returns=
 
     |set=0
 
     |set=0
 
     |text=Number of columns in the DAT table.
 
     |text=Number of columns in the DAT table.
 
}}
 
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=DAT
 
     |class=DAT
 
     |name=numRows
 
     |name=numRows
     |returns=int
+
     |returns=
 
     |set=0
 
     |set=0
 
     |text=Number of rows in the DAT table.
 
     |text=Number of rows in the DAT table.
 
}}
 
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=DAT
 
     |class=DAT
 
     |name=text
 
     |name=text
     |returns=str
+
     |returns=
     |set=1
+
     |set=0
 
     |text=Get or set contents.  Tables are treated as tab delimited columns, newline delimited rows.
 
     |text=Get or set contents.  Tables are treated as tab delimited columns, newline delimited rows.
 
}}
 
}}
 
+
{{ClassMethodSection|empty=}}
{{ClassMember
+
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=locals
+
     |name=insertRow
     |returns=dict
+
     |call=insertRow(vals, nameOrIndex, sort=None)
     |set=0
+
     |returns=
     |text=Local dictionary used during python execution of scripts in this DATThe dictionary attribute is read only, but not its contents. Its contents may be manipulated directly with scripts, or with an [[Examine DAT]].
+
     |text=: -> int
 +
Insert a row to the beginning of the table or before the specified row name/indexSee DAT.appendRow() for similar usage.
 
}}
 
}}
{{ClassMethodSection|empty=False}}
 
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=run
+
     |name=clear
     |call=run([args][, endFrame=False][, fromOP=None][, group=None][, delayFrames=0][, delayMilliSeconds=0][, delayRef=me])
+
     |call=clear(keepSize=False, keepFirstRow=False, keepFirstCol=False)
     |returns=Run
+
     |returns=
     |text=:Run the contents of the DAT as a script, returning a [[Run Class|Run]] object which can be used to optionally modify its execution.
+
     |text=:
:* <code>arg</code> - '''(Optional)''' Arguments that will be made available to the script in a local tuple named <code>args</code>.
+
Remove all rows and columns from the table.
:* <code>endFrame</code> - '''(Keyword, Optional)''' If set to True, the execution will be delayed until the end of the current frame.
+
keepSize - (Keyword, Optional) If set to True, size is unchanged, but entries will be set to blank, dependent on other options below.
:* <code>fromOP</code> - '''(Keyword, Optional)''' Specifies an optional [[OP Class|operator]] from which the execution will be run relative to.
+
keepFirstRow - (Keyword, Optional) If set to True, the first row of cells are retained.
:* <code>group</code> - '''(Keyword, Optional)''' Can be used to specify a group label string. This label can then be used with the [[Runs Class|td.runs]] object to modify its execution.
+
keepFirstCol - (Keyword, Optional) If set to True, the first column of cells are retained.
:* <code>delayFrames</code> - '''(Keyword, Optional)''' Can be used to delay the execution a specific amount of frames.
+
n.clear() #remove all rows and columns
:* <code>delayMilliSeconds</code> - '''(Keyword, Optional)''' Can be used to delay the execution a specific amount of milliseconds. This value is rounded to the nearest frame.
+
n.clear(keepSize=True) #set all table cells to blank
:* <code>delayRef</code> - '''(Keyword, Optional)''' Specifies an optional [[OP Class|operator]] from which the delay time is derived.
+
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
 
}}
 
}}
 
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=save
+
     |name=cells
     |call=save([filepath][, append=False])
+
     |call=cells(rowNameOrIndex, colNameOrIndex, caseSensitive=True)
     |returns=str
+
     |returns=
     |text=:Saves the content of the DAT to the file system. Returns the file path that it was saved to.
+
     |text=: -> list
:* <code>filepath</code> - '''(Optional)''' The path and filename to save the file to. If this is not given then a default named file will be saved to <code>project.folder</code>
+
Returns a (possibly empty) list of cells that match the given row/column names or indices. See DAT.cell method for similar usage.
:* <code>append</code> - '''(Keyword, Optional)''' If set to True and the format is txt, then the contents are appended to the existing file.
 
:Example:
 
::<syntaxhighlight lang=python>
 
# save in native format with default name
 
name = n.save()
 
# human readable format without channel names
 
n.save('output.txt')
 
</syntaxhighlight>
 
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=write
+
     |name=row
     |call=write([args])
+
     |call=row(nameOrIndex1, nameOrIndex2..., caseSensitive=True)
     |returns=str
+
     |returns=
     |text=:Append content to this DAT. Can also be used to implement DAT printing functions.
+
     |text=: -> list
:Examples:
+
Returns a list of cells from the row matching the name/index, or None if nothing is found.
::<syntaxhighlight lang=python>
+
See DAT.col() for similar usage.
# grab DAT
 
n = op('text1')
 
</syntaxhighlight>
 
::<syntaxhighlight lang=python>
 
# append message directly to DAT
 
n.write('Hello World')
 
</syntaxhighlight>
 
::<syntaxhighlight lang=python>
 
# use print method
 
print('Hello World', file=n)
 
</syntaxhighlight>
 
 
}}
 
}}
 
{{SubSection|title=Modifying Content|text=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 [[Lock]]ed.}}
 
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=clear
+
     |name=run
     |call=clear([keepSize=False][,keepFirstRow=False][,keepFirstCol=False])
+
     |call=run(arg1, arg2..., endFrame=False, fromOP=None, group=None, delayFrames=0, delayMilliSeconds=0, delayRef=me)
     |returns=None
+
     |returns=
     |text=:Remove all rows and columns from the table.
+
     |text=: -> Run
:* <code>keepSize</code> - '''(Keyword, Optional)''' If set to True, size is unchanged, but entries will be set to blank, dependent on other options below.
+
Run the contents of the DAT as a script, returning a Run object which can be used to optionally modify its execution.
:* <code>keepFirstRow</code> - '''(Keyword, Optional)''' If set to True, the first row of cells are retained.
+
arg - (Optional) Arguments that will be made available to the script in a local tuple named args.
:* <code>keepFirstCol</code> - '''(Keyword, Optional)''' If set to True, the first column of cells are retained.
+
endFrame - (Keyword, Optional) If set to True, the execution will be delayed until the end of the current frame.
:Examples:
+
fromOP - (Keyword, Optional) Specifies an optional operator from which the execution will be run relative to.
::<syntaxhighlight lang=python>
+
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.
    n.clear() #remove all rows and columns
+
delayFrames - (Keyword, Optional) Can be used to delay the execution a specific amount of frames.
    n.clear(keepSize=True) #set all table cells to blank
+
delayMilliSeconds - (Keyword, Optional) Can be used to delay the execution a specific amount of milliseconds. This value is rounded to the nearest frame.
    n.clear(keepFirstRow=True) #remove all rows, but keep the first
+
delayRef - (Keyword, Optional) Specifies an optional operator from which the delay time is derived.
    n.clear(keepFirstRow=True, keepFirstCol=True) #keep the first row, first column, and set remaining cells to blank
 
</syntaxhighlight>
 
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=copy
+
     |name=cols
     |call=copy(DAT)
+
     |call=cols(nameOrIndex1, nameOrIndex2..., caseSensitive=True)
     |returns=None
+
     |returns=
     |text=:Copy the text or table from the specified [[DAT]] operator.
+
     |text=: -> list of lists
:* <code>OP</code> - The DAT operator whose contents should be copied into the DAT.
+
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'
 
}}
 
}}
 
+
{{ClassMethod
{{SubSection
+
     |class=DAT
     |title=Modifying Text Contents
+
     |name=deleteCol
     |text=When the DAT is not a table, but a block of text, its contents can be simply accessed through its text member.
+
    |call=deleteCol(nameOrIndex)
 
+
     |returns=
Example:
+
     |text=:
:<syntaxhighlight lang=python>
+
Delete a single column at the specified column name or index.
t = op('merge1').text
+
nameOrIndex - May be a string for a column name, or numeric index for column index.
op('text2').text = 'merge1 contains:' + t
 
 
 
op('text3').text = "Hello there!"
 
</syntaxhighlight>
 
}}
 
 
 
{{SubSection
 
     |title=Modifying a Single Cell of a Table
 
     |text=To modify a single cell, where inside the [], integers are the row/column numbers starting at 0, and strings are row or columns names:
 
 
 
Example:
 
::<syntaxhighlight lang=python>
 
tab = op('table1')
 
tab[0,0] = 'corner'
 
tab[1,'select'] = 'yes'
 
tab['Monday',1] = 'day1'
 
</syntaxhighlight>
 
}}
 
 
 
{{SubSection
 
    |title=Modifying Table Contents
 
    |text=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]].
 
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=appendRow
+
     |name=save
     |call=appendRow([vals][,nameOrIndex][,sort])
+
     |call=save(filepath, append=False)
     |returns=int
+
     |returns=
     |text=:Append a row to the end of the table, or after the specified row name/index. Returns the integer index of the new row.
+
     |text=: -> string
:* <code>vals</code> - '''(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 Class|cell]].
+
Saves the content of the DAT to the file system. Returns the file path that it was saved to.
:* <code>nameOrIndex</code> - '''(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.
+
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
:* <code>sort</code> - '''(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.
+
append - (Keyword, Optional) If set to True and the format is txt, then the contents are appended to the existing file.
:Examples:
+
name = n.save() #save in native format with default name
::<syntaxhighlight lang=python>
+
n.save('output.txt') #human readable format without channel names
    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.
 
</syntaxhighlight>
 
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=appendCol
+
     |name=copy
     |call=appendCol([vals][,nameOrIndex][,sort])
+
     |call=copy(DAT)
     |returns=int
+
     |returns=
     |text=:Append a column to the end of the table. See appendRow for similar usage.
+
     |text=:
 +
Copy the text or table from the specified DAT operator.
 +
OP - The DAT operator whose contents should be copied into the DAT.
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=insertRow
+
     |name=insertCol
     |call=insertRow([vals][,nameOrIndex][,sort])
+
     |call=insertCol(vals, nameOrIndex, sort=None)
     |returns=int
+
     |returns=
     |text=:Insert a row to the beginning of the table or before the specified row name/index. See DAT.appendRow() for similar usage.
+
     |text=: -> int
 +
Insert a column to the beginning of the table or before the specified row name/index. See DAT.appendRow() for similar usage.
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=insertCol
+
     |name=rows
     |call=insertCol([vals][,nameOrIndex][,sort])
+
     |call=rows(nameOrIndex1, nameOrIndex2..., caseSensitive=True)
     |returns=int
+
     |returns=
     |text=:Insert a column to the beginning of the table or before the specified row name/index. See DAT.appendRow() for similar usage.
+
     |text=: -> 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'
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
 
     |name=deleteRow
 
     |name=deleteRow
 
     |call=deleteRow(nameOrIndex)
 
     |call=deleteRow(nameOrIndex)
     |returns=None
+
     |returns=
     |text=:Delete a single row at the specified row name or index.
+
     |text=:
:* <code>nameOrIndex</code> - May be a string for a row name, or numeric index for rowindex.
+
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.
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=deleteCol
+
     |name=write
     |call=deleteCol(nameOrIndex)
+
     |call=write(args)
     |returns=None
+
     |returns=
     |text=:Delete a single column at the specified column name or index.
+
     |text=: -> string
:* <code>nameOrIndex</code> - May be a string for a column name, or numeric index for column index.
+
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)
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
 
     |name=setSize
 
     |name=setSize
     |call=setSize(numRows,numCols)
+
     |call=setSize(numrows, numcols)
     |returns=None
+
     |returns=
     |text=:Set the exact size of the table.
+
     |text=:
:* <code>numrows</code> - The number of rows the table should have.
+
Set the exact size of the table.
:* <code>numcols</code> - The number of columns the table should have.
+
numrows - The number of rows the table should have.
}}
+
numcols - The number of columns the table should have.
 
 
{{SubSection
 
    |title=Accessing Table Contents
 
    |text=
 
 
}}
 
}}
 
{{ClassSpecial
 
    |class=DAT
 
    |call=[rowNameOrIndex, colNameOrIndex]
 
    |returns=Cell
 
    |text=:[[Cell Class|cells]] in a table may be accessed with the <code>[]</code> subscript operator.
 
:The NameOrIndex may be an exact string name, or it may be a numeric index value. [[Pattern Matching]] is ''not'' supported.
 
:* <code>rowNameOrIndex</code> - If a string it specifies a row name, if it's numeric it specifies a row index.
 
:* <code>colNameOrIndex</code> - If a string it specifies a column name, if it's numeric it specifies a column index.
 
:Example:
 
::<syntaxhighlight lang=python>
 
c = n[4, 'June']
 
c = n[3, 4]
 
</syntaxhighlight>
 
}}
 
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
 
     |name=cell
 
     |name=cell
     |call=cell(rowNameOrIndex, colNameOrIndex[, caseSensitive=True])
+
     |call=cell(rowNameOrIndex, colNameOrIndex, caseSensitive=True)
     |returns=Cell or None
+
     |returns=
     |text=:Find a single [[Cell Class|cell]] in the table, or None if none are found.
+
     |text=: -> Cell or None
:* <code>rowNameOrIndex/colNameOrIndex</code> - 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.
+
Find a single cell in the table, or None if none are found.
:* <code>caseSensitive</code> - '''(Optional)''' Specifies whether or not case sensitivity is used.
+
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.
:Example
+
caseSensitive - (Optional) Specifies whether or not case sensitivity is used.
::<syntaxhighlight lang=python>
 
 
c = n.cell(5, 'June') #Return a cell under row 5, column 'June'.
 
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.
 
c = n.cell('A*', 2) #Find a cell under any row beginning with an A, in column 2.
</syntaxhighlight>
 
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=cells
+
     |name=appendRow
     |call=cells(rowNameOrIndex, colNameOrIndex[, caseSensitive=True])
+
     |call=appendRow(vals, nameOrIndex, sort=None)
     |returns=list
+
     |returns=
     |text=:Returns a (possibly empty) list of [[Cell Class|cells]] that match the given row/column names or indices. See <code>DAT.cell</code> method for similar usage.
+
     |text=: -> 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.
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
 
     |name=col
 
     |name=col
     |call=col(nameOrIndex[, nameOrIndex2..][, caseSensitive=True])
+
     |call=col(nameOrIndex1, nameOrIndex2..., caseSensitive=True)
     |returns=list
+
     |returns=
     |text=:Returns a list of all the [[Cell Class|cells]] in a column, or None if nothing is found.
+
     |text=: -> list
:* <code>nameOrIndex</code> - If a string it specifies a column name, if it's numeric it specifies a column index. [[Pattern Matching]] is supported.
+
Returns a list of all the cells in a column, or None if nothing is found.
:* <code>caseSensitive</code> - '''(Optional)''' Specifies whether or not case sensitivity is used.
+
nameOrIndex - If a string it specifies a column name, if it's numeric it specifies a column index. Pattern Matching is supported.
:Example:
+
caseSensitive - (Optional) Specifies whether or not case sensitivity is used.
::<syntaxhighlight lang=python>
 
 
r = op('table1').col(3, caseSensitive=False)
 
r = op('table1').col(3, caseSensitive=False)
 
r = op('table1').col('June')
 
r = op('table1').col('June')
 
r = op('table1').col('A*', 'B*') #returns first column beginning with A or B
 
r = op('table1').col('A*', 'B*') #returns first column beginning with A or B
</syntaxhighlight>
 
}}
 
 
{{ClassMethod
 
    |class=DAT
 
    |name=cols
 
    |call=cols(nameOrIndex[, nameOrIndex2..][, caseSensitive=True])
 
    |returns=list of lists
 
    |text=:Returns a (possibly empty) list of columns (each being a list themselves). See <code>DAT.col</code> for similar usage. If no arguments are given then all columns in the table are returned.
 
:* <code>nameOrIndex</code> - '''(Optional)''' If a string it specifies a column name, if it's numeric it specifies a column index. [[Pattern Matching]] is supported.
 
:* <code>caseSensitive</code> - '''(Optional)''' Specifies whether or not case sensitivity is used.
 
:Example:
 
::<syntaxhighlight lang=python>
 
for c in op('table1').cols():
 
# do something with each column 'c'
 
</syntaxhighlight>
 
 
}}
 
}}
 
 
{{ClassMethod
 
{{ClassMethod
 
     |class=DAT
 
     |class=DAT
     |name=row
+
     |name=appendCol
     |call=row(nameOrIndex[, nameOrIndex2..][, caseSensitive=True])
+
     |call=appendCol(vals, nameOrIndex, sort=None)
     |returns=list
+
     |returns=
     |text=:Returns a list of [[Cell Class|cells]] from the row matching the name/index, or None if nothing is found.
+
     |text=: -> int
:See <code>DAT.col()</code> for similar usage.
+
Append a column to the end of the table. See appendRow for similar usage.
 
}}
 
}}
 +
<taggedhistory/>
  
{{ClassMethod
+
{{{{#invoke:Category|list|Python Reference}}}}
    |class=DAT
 
    |name=rows
 
    |call=rows(nameOrIndex[, nameOrIndex2..][, caseSensitive=True])
 
    |returns=list of lists
 
    |text=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 <code>DAT.rows()</code> for similar usage.
 
:Example:
 
::<syntaxhighlight lang=python>
 
for r in op('table1').rows():
 
# do something with row 'r'
 
</syntaxhighlight>
 
}}
 
<section end=HELPBODY />
 
<taggedhistory/>
 
{{#invoke:Category|list|OP Classes|Python Reference}}
 

Revision as of 10:25, 9 August 2017


A DAT describes a reference to a DAT operator.


Members[edit]

export(Read Only):

Get or set export flag

isDAT(Read Only):

True if the operator is a DAT.

isTable(Read Only):

True if the DAT contains table formatted data.

isText(Read Only):

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

locals(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.

module(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)

numCols(Read Only):

Number of columns in the DAT table.

numRows(Read Only):

Number of rows in the DAT table.

text(Read Only):

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

Methods[edit]

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.

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

:

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

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.

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.

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

: -> 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.

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():

  1. do something with each column 'c'

deleteCol(nameOrIndex):

:

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.

save(filepath, append=False):

: -> string

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

copy(DAT):

:

Copy the text or table from the specified DAT operator.

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

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.

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():

  1. do something with row 'r'

deleteRow(nameOrIndex):

:

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.

write(args):

: -> string

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

  1. grab DAT

n = op('text1')

  1. append message directly to DAT

n.write('Hello World')

  1. use print method

print('Hello World', file=n)

setSize(numrows, numcols):

:

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.

cell(rowNameOrIndex, colNameOrIndex, caseSensitive=True):

: -> 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.

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.

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

appendCol(vals, nameOrIndex, sort=None):

: -> int Append a column to the end of the table. See appendRow for similar usage.

TouchDesigner Build:

{list}

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.