Adding an OpScript

To add an OpScript node to a recipe:

1.   Create an OpScript node and connect it to the recipe at the point you want to insert the Lua script.
2.   Select the OpScript node and press Alt+E.

The OpScript node becomes editable within the Parameters tab.

3.   Assign the scene graph locations (or target nodes) this Lua script is to run on to the CEL parameter (see Assigning Locations to a CEL Parameter).
4.   Select when to run the script using the executionMode dropdown:

immediate - runs the script immediately.

deferred - runs the script at a later node in the node graph, as specified by the applyWhen parameter.

5.   If you chose immediate, the applyWhere dropdown is available for you to choose where the script is run:

at all locations - at all the locations in the node graph.

at specific locations - at only the location specified by the location parameter. If this location doesn't exist, it is created automatically.

at locations matching CEL - at only those locations in the node graph that match the CEL statements.

If you chose deferred, the applyWhen dropdown is available for you to choose when the script is run, if not immediately:

during op resolve - the script and its arguments are added as attributes to be executed later by an OpResolve node.

during material resolve - the script and its arguments are added as attributes under the material.scenegraphLocationModifers group attribute.

during katana look file resolve - the script and its arguments are added as attributes under the Scene GraphLocationModifers group attribute and are evaluated by a LookFileResolve node or by the first implicit resolver if no LookFileResolve node is present.

Note:  Each of the applyWhen options has additional parameters that are available, depending on which you choose. See the All the 2D nodes that you can use within Katana. section for more information.

6.   If you chose immediate, set the inputBehavior dropdown. This controls how input ports on the node are mapped onto the inputs of the underlying Op, and is only meaningful when the node has one or more invalid input ports - a port that is not connected to an output port or is connected to an output port that doesn't provide data.

If you chose deferred, set the modifierNameMode dropdown to either:

node name - deferred OpScripts are added as group attributes within the "Ops" group, and the name of the node is used for the sub-group. Since node names must be unique in project, the resulting attribute name can change.

specified - use a fixed name for the OpScript sub-group.

7.   In certain instances, such as when executionMode is set to immediate, or when it is set to deferred, during op resolve, the resolveIds parameter displays. Specify the resolveIds in the form of "resolveName1", "resolveName2" and so on. This ensures the OpScript is resolved only by the op resolvers that contain a matching resolve ID.
8.   If you choose deferred, and set the applyWhen parameter to either during op resolve or during katana look file resolve, you can set the recursiveEnable parameter. Enabling this parameter results in the script being run at every location beneath the assigned locations. This is far more efficient than using the equivalent recursive CEL statement.
9.   If you want to set the OpScript node to have multiple inputs, tick the Display as multi-input box. By default, this box isn't ticked.
10.   Finally, enter the Lua script in the script parameter.

Tip:  To have an OpScript, running at multiple locations, use the same stable, random numbers at each location, the math.randomseed() and math.random() functions can be used. OpScript's math.randomseed() and math.random() implementations use re-entrant pseudo-random number generation functions, and implement the default flavors available in Lua.

local seed = math.randomseed()

local randVal_01 = math.random(1, 10)

local randVal_02 = math.random(11, 20)

local randVal_03 = math.random(21, 30)