Difference between revisions of "Cell Class"

From TouchDesigner Documentation
Jump to: navigation, search
(Cell Class Auto Create)
 
(Tag: 2018.28070)
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{lowercase}}
+
{{TDClassSummary|label=Cell|summary=The [[Cell Class]] describes the contents of a single cell from a [[DAT]] operator table.
{{TDClassSummary|summary=The Cell Class describes the contents of a single cell from a DAT operator table.
+
The [[DAT Class]] offers many ways of accessing its individual cells.
The DAT Class offers many ways of accessing its individual cells.
+
[[DAT]] cells are always internally stored as strings, but may be accessed as numeric values.}}
DAT cells are always internally stored as strings, but may be accessed as numeric values.}}
+
<section begin=HELPBODY />
{{ClassMemberSection|empty=}}
+
{{ClassMemberSection|empty=
 +
|Sectionsummary=
 +
|items=
 
{{ClassMember
 
{{ClassMember
 
     |class=Cell
 
     |class=Cell
     |name=owner
+
     |name=valid
     |returns=
+
     |type=bool
 
     |set=0
 
     |set=0
     |text=The OP to which this object belongs.
+
     |text=True if the referenced cell currently exists, False if it has been deleted.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Cell
 
     |class=Cell
     |name=val
+
     |name=row
     |returns=
+
     |type=int
 
     |set=0
 
     |set=0
     |text=Get or set the cell contents, which are always stored as a string value.
+
     |text=The numeric row of the cell.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Cell
 
     |class=Cell
     |name=valid
+
     |name=col
     |returns=
+
     |type=int
 
     |set=0
 
     |set=0
     |text=True if the referenced cell currently exists, False if it has been deleted.
+
     |text=The numeric column of the cell.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Cell
 
     |class=Cell
     |name=col
+
     |name=owner
     |returns=
+
     |type=OP
 
     |set=0
 
     |set=0
     |text=The numeric column of the cell.
+
     |text=The [[OP Class|OP]] to which this object belongs.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=Cell
 
     |class=Cell
     |name=row
+
     |name=val
     |returns=
+
     |type=value
     |set=0
+
     |set=1
     |text=The numeric row of the cell.
+
     |text=Get or set the cell contents, which are always stored as a string value.
}}
+
}}}}
{{ClassMethodSection|empty=}}
+
{{ClassMethodSection|empty=
 +
|Sectionsummary=
 +
|items=
 +
 +
{{ClassMethod
 +
    |class=Cell
 +
    |name=run
 +
    |call=run(endFrame=False, fromOP=None, asParameter=False, group=None, delayFrames=0, delayMilliSeconds=0, delayRef=me, arg1, arg2...)
 +
    |returns=td.Run
 +
    |text=[[Run Class|Run]] the contents of the cell as a script, returning a Run object which can be used to optionally modify its execution.
 +
*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 [[OP Class|operator]] from which the execution will be run relative to.
 +
*asParameter - (Keyword, Optional) When fromOP used, run relative to a parameter of fromOP.
 +
*group - (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.
 +
*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 [[OP Class|operator]] from which the delay time is derived.
 +
*arg - (Optional) Arguments that will be made available to the script in a local tuple named args.}}
 
{{ClassMethod
 
{{ClassMethod
 
     |class=Cell
 
     |class=Cell
 
     |name=offset
 
     |name=offset
 
     |call=offset(r, c)
 
     |call=offset(r, c)
     |returns=
+
     |returns=td.Cell or None
     |text=: -> Cell or None
+
     |text=The cell offset to this cell by the specified amount, or None.
The cell offset to this cell by the specified amount, or None.
+
*r - The number of rows from the cell.  Positive values count down, while negative values count up.
r - The number of rows from the cell.  Positive values count down, while negative values count up.
+
*c - The number of columns from the cell.  Positive values count right, while negative values count left.
c - The number of columns from the cell.  Positive values count right, while negative values count left.
+
<syntaxhighlight lang=python>
 
c = op('table1')['March', 'Sales']
 
c = op('table1')['March', 'Sales']
 
d = c.offset(-1, 2)  # one row up, two columns right of cell C
 
d = c.offset(-1, 2)  # one row up, two columns right of cell C
 +
</syntaxhighlight>
 +
}}
 +
{{SubSection|title=Casting to a Value
 +
|text=The Cell Class implements all necessary methods to be treated as a number or a string, which in this case gets or sets its value. Therefore, an explicit call to get or set val is unnecessary when used in a parameter, or in an expression.
 +
For example, the following are equivalent in a numeric parameter:
 +
<syntaxhighlight lang=python>
 +
(float)n[1,2]
 +
n[1,2].val
 +
n[1,2]
 +
</syntaxhighlight>
 +
Or equivalently, for a string parameter:
 +
<syntaxhighlight lang=python>
 +
(str)n[1,2]
 +
n[1,2].val
 +
n[1,2]
 +
</syntaxhighlight>
 +
Similarly, expressions on Cells will autocast themselves automatically:
 +
<syntaxhighlight lang=python>
 +
n[1,2].val + 1 # string plus 1, error
 +
n[1,2] + 1 # autocasted value plus 1
 +
</syntaxhighlight>
 +
In the second case, the contents of the Cell are used to determine if numeric or string operations should be used.
 +
For example, if cell n[1,2] contains "3" then:
 +
<syntaxhighlight lang=python>
 +
n[1,2].val + n[1,2].val # will return "33" since .val is a string.
 +
</syntaxhighlight>
 +
However,
 +
<syntaxhighlight lang=python>
 +
n[1,2] + n[1,2] # will return 6 since the contents "3" are numeric.
 +
</syntaxhighlight>
 +
If n[1,2] contained a non-numeric value such as "a" then
 +
<syntaxhighlight lang=python>
 +
n[1,2] + n[1,2] # will return "aa"
 +
</syntaxhighlight>
 
}}
 
}}
{{ClassMethod
 
    |class=Cell
 
    |name=run
 
    |call=run(endFrame=False, fromOP=None, , group=None, delayFrames=0, delayMilliSeconds=0, delayRef=me, arg1, arg2...)
 
    |returns=
 
    |text=: -> Run
 
Run the contents of the cell as a script, returning a Run object which can be used to optionally modify its execution.
 
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.
 
arg - (Optional) Arguments that will be made available to the script in a local tuple named args.
 
 
}}
 
}}
<taggedhistory/>
+
<section end=HELPBODY />
 
+
{{History}}
{{{{#invoke:Category|list|Python Reference}}}}
+
{{#invoke:Category|list|Python Reference}}

Latest revision as of 12:44, 6 March 2019

The Cell Class describes the contents of a single cell from a DAT operator table. The DAT Class offers many ways of accessing its individual cells. DAT cells are always internally stored as strings, but may be accessed as numeric values.


Members[edit]

validbool (Read Only):

True if the referenced cell currently exists, False if it has been deleted.

rowint (Read Only):

The numeric row of the cell.

colint (Read Only):

The numeric column of the cell.

ownerOP (Read Only):

The OP to which this object belongs.

valvalue :

Get or set the cell contents, which are always stored as a string value.

Methods[edit]

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

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

  • 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.
  • asParameter - (Keyword, Optional) When fromOP used, run relative to a parameter of fromOP.
  • 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.
  • arg - (Optional) Arguments that will be made available to the script in a local tuple named args.

offset(r, c)td.Cell or None:

The cell offset to this cell by the specified amount, or None.

  • r - The number of rows from the cell. Positive values count down, while negative values count up.
  • c - The number of columns from the cell. Positive values count right, while negative values count left.
c = op('table1')['March', 'Sales']
d = c.offset(-1, 2)  # one row up, two columns right of cell C

Casting to a Value[edit]

The Cell Class implements all necessary methods to be treated as a number or a string, which in this case gets or sets its value. Therefore, an explicit call to get or set val is unnecessary when used in a parameter, or in an expression. For example, the following are equivalent in a numeric parameter:

(float)n[1,2]
n[1,2].val
n[1,2]

Or equivalently, for a string parameter:

(str)n[1,2]
n[1,2].val
n[1,2]

Similarly, expressions on Cells will autocast themselves automatically:

n[1,2].val + 1 # string plus 1, error
n[1,2] + 1 # autocasted value plus 1

In the second case, the contents of the Cell are used to determine if numeric or string operations should be used. For example, if cell n[1,2] contains "3" then:

n[1,2].val + n[1,2].val # will return "33" since .val is a string.

However,

n[1,2] + n[1,2] # will return 6 since the contents "3" are numeric.

If n[1,2] contained a non-numeric value such as "a" then

n[1,2] + n[1,2] # will return "aa"

TouchDesigner Build:

Any of the procedural data operators. OPs do all the work in TouchDesigner. They "cook" and output data to other OPs, which ultimately result in new images, data and audio being generated. See Node.