Houdini 19.0 Nodes Geometry nodes Switch-If

Switch-If geometry node

Switches between two network branches based on an expression or geometry test.

On this page
Since 18.0

Overview

This node switches between passing through the first or second input. If you use a single test on an expression, then this is equivalent to a Switch SOP. However, this node also lets you test certain aspects of the incoming geometry, and also combine multiple tests using “All conditions true” (AND) or “Any conditions true” (OR) logic.

See the Test type parameter below for the list of tests you can run on incoming geometry.

Note

This node will pass one of the two inputs through unchanged, it does not apply the switching on a per-point or per-primitive level.

Examples

To...Do this

Use “default” geometry if an asset’s input isn’t connected

  1. Wire the “default” geometry into the Switch If node’s first input.

  2. Wire the subnet input you want to test into the second input.

  3. Set Test input to “Second input”.

  4. Set Test type to “Input connected”.

Report an error in an asset if an input doesn’t have at least one point

  1. Wire an Error SOP to the Switch If node’s first input. Set the Error message, set Severity to “Error”, and set Report this error to 1.

  2. Wire the subnet input you want to test into the second input.

  3. Set Test input to “Second input”.

  4. Set Test type to “Element count”, and configure the rest of the parameters:

    Enable when

    “Number of Points”

    Is

    “Greater than”

    Value

    0

If the second input has at least one point, it will flow down. Otherwise, the error will propagate down instead.

Tips

  • To test if the parent asset has an input wired, you can use the expression opinputpath("..", n) where n is the input number to test (starting at 0).

Inputs

First (False)

Passed through if the test returns False (or 0).

Second (True)

Passed through if the test returns True (or non-zero).

(You might intuitively expect True to be first, but this order makes the most sense considering that for expressions and scripting the inputs are numbered 0 and 1.)

Parameters

Use Second Input If

How to decide whether to pass through the second input, based on the results of the test(s) below.

All conditions true

Pass through the second input if all tests evaluate to True (or non-zero).

Any condition true

Pass through the second input if any tests evaluate to True (or non-zero).

All conditions false

Pass through the second input if all tests evaluate to False (or 0).

Any condition true

Pass through the second input if any tests evaluate to False (or 0).

Test Input

For tests below based on geometry, use the geometry from this input. The chosen input always cooks.

First input

Test the geometry wired into the first input.

Second input

Test the geometry wired into the second input.

Spare input 0

Test the geometry in the node at a certain node path.

If you choose this option, a script automatically adds a spare node path parameter for you. If you then choose another option, the spare parameter remains (unless you manually delete it), however it will only be used if Test input is set to this option.

Number of tests

This node can run multiple tests (with the results combined using the Use second input if parameter). Set this to the number of tests you want to run, or click the plus and minus buttons to add or remove tests.

Test Type

What type of test to perform.

Expression

Evaluates an HScript expression in the Enable parameter. If the expression returns a value (rounded to the nearest integer) other than 0, it is considered True.

Attribute Presence

Tests whether the geometry has (or doesn’t have) an attribute with the given name. Configure this test using the Enable when, Class, and Attributes parameters.

Element count

Tests based on the number of components (points, primitives, vertices) in the geometry. Configure this test using the Enable when, In group, Is, and Value parameters.

Attribute value

Tests whether a given attribute on the first point, primitive, or vertex† matches a certain value. Configure this test using the Class, Attributes, Of type, Is, and Value parameters.

†Normally, this test only tests against the first attribute value it finds. However, for string attributes, you can use the comparison “Containing Any Element Matching”, which is True if any attribute value in the geometry matches the pattern in Value.

Input wired

Is True if the input specified in Test input has geometry wired into it. If Test input is “Spare input 0”, this is True if the node at the path in the spare input exists.

See also

Switch-If