Par Class

From TouchDesigner 099 Wiki

The Par class describes an instance of a single Parameter. See also Custom Parameters.

Members

valid (Read Only) True if the referenced parameter currently exists, False if it has been deleted.
val Get or set the constant value of the parameter only.

op('geo1').par.tx.val = 5   
op('geo1').par.tx = 5  #equivalent to above, more concise form

When setting this member, the parameter will also be placed in constant mode. See mode member below.
To get the parameter's current value, regardless if it's from a constant, expression, or export, use the eval() method described below. To set a menu value by its index, use the menuIndex member as described below.

expr Get or set the non-evaluated expression only.

op('geo1').par.tx.expr = 'me.time.frame'  #set to match current frame

When setting this member, the parameter will also be placed in expression mode. See mode member below.
To get the parameter's current value, regardless if it's from a constant, expression, or export, use the eval() method described below.
NOTE: For convenience, the expression is placed in double-quotes so you can safely put in expressions containing single quotes. 'a' and "a" have the same effect of enclosing strings in python.

exportOP (Read Only) The operator exporting to this parameter.
index (Read Only) The parameter's order in the list.
vecIndex (Read Only) The parameter's vector index. For example, op('geo1').par.tz would have a value of 2.
name Get or set the parameter's unique name. Example: Translate. Can only be set on Custom Parameters.
label Get or set the parameter's label. Example: Translate. Can only be set on Custom Parameters.
startSection Get or set the parameter's separator status. When True a visible separator is drawn between this parameter and the ones preceding it. Can only be set on Custom Parameters.
readOnly Get or set the parameter's read only status. When True the parameter cannot be modified through the UI, only scripting.
tuplet (Read Only) The tuplet of parameters this parameter belongs to. A tuplet is typically a set of parameters sharing one line on a parameter dialog, example: Translate (x, y, z).
tupletName (Read Only) The tuplet name of a parameter. Example: The tuplet name of a (tx,ty,tz) translate parameter is t.
min Get or set the parameter's numerical minimum value. The parameter's value will be clamped at that minimum if clampMin = True. Can only be set on Custom Parameters.
max Get or set the parameter's numerical maximum value. The parameter's value will be clamped at that maximum if clampMax = True. Can only be set on Custom Parameters.
clampMin Get or set the parameter's numerical clamping behavior. If set to clampMin = True, the parameter will clamp on the lower end at the value specified in min Can only be set on Custom Parameters.
clampMax Get or set the parameter's numerical clamping behavior. If set to clampMax = True, the parameter will clamp on the upper end at the value specified in max Can only be set on Custom Parameters.
default Get or set the parameter's default value. Can only be set on Custom Parameters. Only one of default, defaultExpr can be set.
defaultExpr Get or set the parameter's default expression. Can only be set on Custom Parameters. Only one of default, defaultExpr can be set.

op('base1').par.Size.defaultExpr = 'me.time.frame'  #value defaults to this expression.

normMin Get or set the parameter's minimum slider value if the parameter is a numerical slider. Can only be set on Custom Parameters.
normMax Get or set the parameter's maximum slider value if the parameter is a numerical slider. Can only be set on Custom Parameters.
normVal Get or set the parameter's value as a normalized slider position. Can only be set on Custom Parameters.
enable Get or set the parameter's enable state. Can only be set on Custom Parameters.
order The custom parameter's position on the parameter page. Can only be set on Custom Parameters.
page The custom parameter page the parameter is part of. Can only be set on Custom Parameters.
mode Get or set the parameter's evaluation mode.

op('geo1').par.tx.mode = ParMode.EXPRESSION

The mode is one of: ParMode.CONSTANT, ParMode.EXPRESSION, or ParMode.EXPORT.
See Parameter_Dialog#Working_with_Parameter_Modes for more information.

prevMode (Read Only) The parameter's previous evaluation mode.
menuNames Get or set a list of all possible menu choice names. In the case of non menu parameters, None is returned. Can only be set on Custom Parameters.
menuLabels Get or set a list of all possible menu choice labels. In the case of non menu parameters, None is returned. Can only be set on Custom Parameters.
menuIndex Get or set a menu constant value by its index.
menuSource Get or set an expression that returns an object with .menuItems .menuNames members. This can be used to create a custom menu whose entries dynamically follow that of another menu for example. Example: p.menuSource = "op('audiodevin1').par.device". Note the outside quotes, as menuSource is an expression, not an object.
owner (Read Only) The OP to which this object belongs.
isDefault (Read Only) True when the parameter value, expression and mode are in their default settings.


Type Members

isPulse (Read Only) True for pulse parameters.
isMomentary (Read Only) True for momentary parameters.
isMenu (Read Only) True for menu parameters.
isNumber (Read Only) True for numeric parameters.
isFloat (Read Only) True for floating point numeric parameters.
isInt (Read Only) True for integer numeric parameters.
isOP (Read Only) True for OP parameters.
isPython (Read Only) True for python parameters.
isString (Read Only) True for string parameters.
isToggle (Read Only) True for toggle parameters.
style (Read Only) Describes the behavior and contents of the custom parameter. Example 'Float', 'Int', 'Pulse', 'XYZ', etc.
isCustom (Read Only) True for Custom Parameters.

Menu Parameters

Menu parameters can be get or set by specifying either the string value of the menu, or its numeric index. For example, the following are equivalent:

  • op('geo1').par.xord = 'trs'
  • op('geo1').par.xord = 5


Alternatively, the menu can be accessed more directly:

n = op('geo1')
n.par.xord.menuIndex = 5  #trs
a = n.menuNames[0]  #returns 'srt'
b = n.menuLabels[0] #returns 'Scale Rotate Translate'



Methods

copy(Par)

Copy the specified parameter.
  • Par - The parameter to copy.
   op('geo1').par.tx.copy( op('geo2').par.tx )

eval()value

Evaluate a parameter. This value may be derived by the parameter's constant value, expression, or export, dependent on its mode.
   a = op('geo1').par.tx.eval()

evalNorm()value

Similar to eval() but the returns the normalized slider value.

evalExpression()value

Evaluate the expression portion of a parameter, if it contains one. This will ignore any exports, etc.
   a = op('geo1').par.tx.evalExpression()
To evaluate an arbitrary expression string, that is not inside a parameter, see OP.evalExpression.

evalExport()value

Evaluate the export portion of a parameter, if it contains one. This will ignore any expressions, etc.
   a = op('geo1').par.tx.evalExport()

evalOPs()list

Evaluate the parameter as series of operators. This is useful for a custom parameter that specifies a list of operator paths for example.
   a = op('base1').par.Paths.evalOPs()

pulse(value, frames=nframes, seconds=nseconds)

Pulsing sets a parameter to the specific value, cooks the operator, then restores the parameter to its previous value.
No value is necessary when the parameter is an actual pulse type.
  • value - (Optional) The value to pulse this parameter with, default is 1.
  • frames - (Optional) Number of frames before restoring the parameter to its original value.
  • seconds - (Optional) Number of seconds before restoring the parameter to its original value.
   op('moviein1').par.reload.pulse(1)  #set the reload toggle, then cook
   op('glsl1').par.loadvariablenames.pulse() #activate the pulse parameter
   op('geo1').par.ty.pulse(2, frames=120) #pulse geometry ty for 120 frames
   op('text1').par.text.pulse('GO!', seconds=3)#pulse text TOP string field, for 3 seconds
   op('noise').par.type.pulse('random', seconds=0.5)#pulse noise meny type for half a second

destroy()

Destroy the custom parameter referenced by this Par. An exception will be raised if the parameter has already been destroyed.


Miscellaneous

__getstate__()dict

Returns a dictionary with persistent data about the object suitable for pickling and deep copies.

__setstate__(dict)

Reads the dictionary to update persistent details about the object, suitable for unpickling and deep copies.


Casting to a Value

The Par Class implements all necessary methods to be treated as a number or string, which in this case gets or sets its value. Therefore, an explicit call to eval() or set() is unnecessary when used in a parameter, or in a numeric expression.

For example, the following are equivalent in a parameter:

  • (float)me.par.tx
  • me.par.tx.eval()
  • me.par.tx


The following are also equivalent:

  • me.par.tx.eval() + 1
  • me.par.tx + 1


as are the following:

  • me.par.tx.val = 3
  • me.par.tx = 3