Houdini 21.0 Nodes Copernicus nodes

Python Snippet Copernicus node

Runs a snippet of Python on layers.

On this page

This node provides an interface that lets you run Python code on layers and geometry.

Warning

Though Python can be easy to write, it’s CPU-based and intepreted. Since using Python for per-pixel operations is slow, use OpenCL or VEX for these operations.

The Signature tab controls the inputs and outputs of the node and the Bindings tab controls the bound parameters. Each Bind# parameter is a fixed constant value that’s evaluated before the Python code in the Kernel tab runs. The bindings are in the provided kwargs dictionary, which means the Python code runs independently from any particular node (see Syntax for more information).

Warning

You can’t bind geometry as a layer, you must refer to it by name in an attribute or volume binding.

Note

Unless you're configuring a special use case, you usually don’t need to manually edit the Signature or Bindings tabs. Instead, click the button in the Kernel tab to set up those tabs.

You can use this node to interface with third-party Python code to solve a problem (for example, using Qt to render images).

Note

Unlike the Python Script SOP, this node can’t access the currently evaluating node. This separates the cooking from the node network.

Syntax

The script you write has a kwargs object with all of the inputs and bound parameters available. The kwargs object returns a dictionary of the specified outputs.

Similar to the OpenCL snippets, you can use the #bind syntax to define the signature and bound parameters in the code. Python treats these commands as comments so the evaluation ignores them, but the button uses them to set up the signatures and bindings.

Parameters

Kernel

Python Code

The Python code to run.

Use the provided kwargs dictionary, which contains the bound parameters and input geometry and layers, to return a dictionary of named outputs. You can also use the #bind syntax to define the signature and bound parameters. The button sets up the Signature and Bindings tabs.

Options

Maintain State

When on, the node doesn’t clear the underlying Python interpreter between cooks. This can enhance performance, but may result in unexpected behavior. It’s recommended to turn this off in most scenarios.

Signature

Inputs

The number of this node’s inputs.

Input #

The name of the input, which is what you reference in the #bind command.

Type

The data type or port for the node input.

Varying

Accepts mono, UV, RGB, or RGBA layers.

All inputs of Varying type are set to the same type. The Varying type matches the input’s signature, and the signature must be the same type for all Varying inputs. If available, the signature matching selects the signature that fits.

ID

Accepts ID layers.

Mono

Accepts mono layers.

UV

Accepts UV layers.

RGB

Accepts RGB layers.

RGBA

Accepts RGBA layers.

Geometry

Accepts a geometry type. You must refer to this type’s name in an attribute or volume binding.

Metadata

This input isn’t read, but used only for size and metadata information.

Integer VDB

Accepts integer VDBs.

Float VDB

Accepts float VDBs.

Vector VDB

Accepts vector VDBs.

Varying VDB

Accepts float or vector VDBs.

Optional

Makes the input optional. When on, make sure to mark the corresponding binding as optional.

Outputs

The number of this node’s outputs.

Output #

The name of the output, which is what you reference in the #bind command.

Type

The data type or port for the node output.

Varying

A mono, UV, RGB, or RGBA layer that matches the corresponding Varying input layers.

ID

An ID layer.

Mono

A mono layer.

UV

A UV layer.

RGB

An RGB layer.

RGBA

An RGBA layer.

Geometry

A geometry type.

Integer VDB

An integer VDB.

Float VDB

A float VDB.

Vector VDB

A vector VDB.

Varying VDB

A float or vector VDB.

Bindings

Bindings

The number of this node’s bound parameters.

Expand a Bind# parameter’s dropdown menu to configure its Name, Type, and other values.

Name

The name of the parameter. This is the value used in the kwargs dictionary.

Type

The type of parameter to create and bind.

Integer

A constant integer value, which lets you bind pre-computed channel references and expressions.

Float

A constant float value.

Vector2

A constant tuple of two floats.

Vector

A constant tuple of three floats.

Vector4

A constant tuple of four floats.

Ramp

A floating point (spline) ramp or RGB color ramp. This becomes a hou.Ramp object.

String

A constant string value.

Value

The value to use for the set Type's parameters.

When Type is set to

  • Integer, this is the integer value used for integer parameters.

  • Float, this is the float value used for float parameters.

  • Vector2, this is the float2 value used for float2 parameters.

  • Vector, this is the float3 value used for float3 parameters.

  • Vector4, this is the float4 value used for float4 parameters.

  • String, this is the string value used for string parameters.

Note

This parameter doesn’t apply when the Type is Ramp.

Data Type

When Type is Ramp, this is the type of ramp to bind.

Float

Bind a floating point (spline) ramp.

Vector

Bind an RGB color ramp.

Ramp

The floating point (spline) ramp or RGB color ramp. See Ramp parameters for more information.

Inputs

input#

The source layer on which to apply the Python code. The amount of node inputs and their details are based on the Inputs information in the Signature tab.

Outputs

output#

The output layer with the Python code applied. The amount of node outputs and their details are based on the Outputs information in the Signature tab.

See also

Copernicus nodes