Houdini 22.0 Character KineFX

Built-in functions in APEX Script

Use the built-in functions provided by APEX Script.

On this page

A function is a block of code that performs a specific operation. In APEX Script, you can use the built-in APEX functions (described on this page) or create your own functions.

The library of built-in functions supported by APEX Script can be found in the APEX nodes index, the APEX network view tab menu, or the autocomplete feature when typing in the Snippet parameter of the APEX Script SOP or APEX AutoRig Component SOP. These built-in functions can be called using either a function-based syntax or an object-oriented syntax.

Function-based vs object-oriented syntax

In the function-based syntax, you call the APEX node as a function, prefixed with its namespace. In the object-oriented syntax, the first argument of a function is the “object” the function operates on, and it’s placed before the function call. The namespace is omitted in the object-oriented syntax.

arr1 = ['aaa']

# Function-based syntax using the APEX and array namespaces
arr2 = apex.array.append(arr1, 'bbb')

# Object-oriented syntax
arr1.append('ccc')

Note

The first letter of the function call to an APEX node can be uppercase or lowercase. For example, calling graph.AddNode() is the same as calling graph.addNode().

Function-based syntax

The example below calls the append() function using the APEX and array namespaces. The first argument of append() is an in-place port, so the input array, x, is updated:

x = ['aaa']

x = apex.array.append(x, 'bbb')

# Result: x = ['aaa', 'bbb']

If the result of append() is assigned to a different variable, the original array is not updated:

x = ['aaa']

y = apex.array.append(x, 'bbb')

# Result: x = ['aaa'], y = ['aaa', 'bbb']

Functions without a namespace (for example, Sine()) do not need to be prefixed with the APEX namespace:

# With the APEX namespace
a = apex.sine(1.0)

# Without the APEX namespace
b = sine(1.0)

Object-oriented syntax

In the object-oriented syntax, the first argument of a function is the “object” the function operates on, and it’s placed before the function call. This object is then passed to the function as the first argument. If this first argument is an in-place port, it is updated in-place:

x = ['aaa']

x.append('bbb')

# Result: x = ['aaa', 'bbb']

If the object-oriented append() is assigned to a variable, the variable is set to the 2nd return value of append():

x = ['aaa']

idx = x.append('bbb')

# Result: x = ['aaa', 'bbb'], idx = 1

If the first argument of a function is not an in-place port, the argument is not updated:

x = ['aaa','bbb','ccc']

y = x.get(1)

# Result: x = ['aaa', 'bbb', 'ccc'], y = 'bbb'

Function versions

When an APEX Script SOP is first created, the current Houdini version is recorded as part of the APEX Script header text (in the Application Version parameter). When you call a function in APEX Script, the latest version of the function in that Houdini version is used. You can also call an exact version of an APEX function - for example, IntBitMaskToBool.v2_0() calls the second version of IntBitMaskToBool. See the special function HoudiniVersion() for more information on how to use a specific version of an APEX function.

More function examples

Call a function with arguments:

box = apex.sop.box(t=Vector3(1,1,1), scale=Float(2))

Functions that operate on different types

Functions that operate on different types of data are called templated functions. For example, geo::SetPrimAttribValue<T> is a templated function, where <T> could be one of several different types. Templated functions can be specified in the following ways:

Use the function name suffixed by the type, for example, add “_String” to the function name:

geo.setPrimAttribValue_String(prim, 'name', 'test')

Use the valuetype argument to specify the type, valuetype=<type>:

geo.setPrimAttribValue(prim, 'name', 'test', valuetype=String)

The valuetype argument can be a list or tuple:

b = Convert(a, valuetype=(Float, Int))

c = Convert(b, valuetype=[Int, Bool])

Special functions

APEX Script provides special functions that allow you to perform various graph operations, including the ability to add information to graph nodes, use a specific version of APEX nodes, and invoke graphs from within a graph.

Function

Description

BeginMetadata, EndMetadata

Sets metadata on the block begin and end nodes for loops and if blocks (for example, ForBegin, IfEnd). The available metadata are listed in the special function arguments.

y = 0

for x in range(3):
    # Set metadata on ForBegin node
    BeginMetadata(__name='test_begin', __color=(1,0,1), __tags=['tag1', 'tag2'])

    y = y + 1

    # Set metadata on ForEnd node
    EndMetadata(__name='test_end', __pos=(1,1,1), __tags=['out_tag'])

BindInput, BindOutput

Defines the inputs and outputs of a graph. For more information, see this example for how to use BindInput() and BindOutput(), and see specifying graph inputs for example uses of BindInput().

HoudiniVersion

Sets the version of the APEX functions to use. For example, HoudiniVersion('20.5.250') tells APEX Script to use the set of APEX functions from Houdini version 20.5.250.

You could also specify the Houdini version in the header template:

  1. Turn on the Header parameter.

  2. In the Header section, turn on Add Version.

  3. Turn on Edit to change the Houdini version.

Two other arguments are available for use with the HoudiniVersion() function - newest and ignore.

  • HoudiniVersion('newest') - Uses the newest versions of the APEX functions.

  • HoudiniVersion('ignore') - Uses the exact version of the APEX function that is called. For example, IntBitMaskToBool() calls the first version of the function. If you want to use the second version of IntBitMaskToBool, call IntBitMaskToBool.v2_0().

If HoudiniVersion() is not present, this is the same as calling HoudiniVersion('ignore').

InputMetadata, OutputMetadata

Sets metadata on the graph input (parms) and output nodes inside a subnet. The available metadata are listed in the special function arguments.

def test(a,b):
    # Set metadata on subnet input node
    InputMetadata(__name='abc', __pos=(1,0,0), __properties={'test': 1.5})

    c: Float = a + b

    # Set metadata on subnet output node
    OutputMetadata(__color=(1,0,1), __tags=['out_tag1','out_tag2'])

    return c

x = test(1,2)

InvokeOutputs

See invoking a graph.

SetGraph

See associating APEX node IDs to a graph.

StickyNote

Creates sticky notes in the graph. The arguments listed below, in addition to the special function arguments, can be used to set certain properties on the sticky note:

Argument

Type

contents

String

dimensions

Vector2

is_background_hidden

Bool

is_collapsed

Bool

text_color

Vector3

text_size

Float

Example:

StickyNote(contents='hello', dimensions=(3.0, 3.0), is_background_hidden=False, is_collapsed=False, text_color=(1.0, 0.0, 0.0), text_size=0.0, __color=(0,0,1))

_portalias

Creates another identifier for a variable without making a copy. This could introduce graph sorting issues, so use with caution.

Create an alias of a variable:

x = 1.5
y = _portalias(x)

# y = 1.5
BindOutput(y)

Create an alias of a variable that is assigned to a function:

def test():
    x = 1
    return x

m = test()
m_alias = _portalias(m)

# m_alias = 1, n = 3
n = m_alias + 2

Use an alias in a function:

def test(a: Int, b: Int):
    c: Int = a + b
    d = _portalias(c)
    d += 2
    return d

# m = 5
m = test(1, 2)

Invoking another graph

InvokeOutputs() is a special function that is used to execute another graph. When you have an input that is a graph, InvokeOutputs() is used to execute that graph input.

In this example, InvokeOutputs() executes the function foo:

def foo (a: Int, b: Int) -> tuple[Int, Int]:
    return b, a

x: Int
y: Int

x, y = InvokeOutputs(foo, parms={"a": 1, "b": 2}, outputs=["output:a", "output:b"])
Logic to invoke another graph
Function foo being invoked

The syntax of InvokeOutputs() is:

InvokeOutputs(<function>, parms=<dict>, outputs=[array of strings])

where:

  • parms - Dictionary of parameter values to pass into the function.

  • outputs - An array of strings that specify the values returned by the function. The strings are in the format <output_node>:<output_port>, where <output_node> is the output node in the function graph (function foo, in our case).

The outputs argument is matched up with the function return values. In the example above:

  • output:a is set to function return value a. Variable x is then set to output:a.

  • output:b is set to function return value b. Variable y is then set to output:b.

If the function return statement contains an expression, set the outputs argument to result<x>, where x is the position of the function return value starting at 0:

def foo(a: Int):
    return a+1

x: Int = InvokeOutputs(foo, parms={"a": 1}, outputs=["output:result0"])

# Different way of specifying the return value type
y = Int(InvokeOutputs(foo, parms={"a": 2}, outputs=["output:result0"]))

If the function return statement contains multiple expressions, the order of the return values is important. For the return values that are not expressions, the corresponding outputs argument must be set to output:<variable>:

# Function return values using expressions (a+b and a*b)
def foo(a: Int, b: Int):
    return a+b, a, a*b

x: Int
y: Int
z: Int

# Function returns a+b in output:result0, and
# a*b in output:result2
x, y, z = InvokeOutputs(foo, parms={"a": 1, "b": 2}, outputs=["output:result0", "output:a", "output:result2"])

Tip

It is more readable and less error-prone for a function to return only variables and not expressions.

Retrieve only certain values from the function:

def foo(a: Int, b: Int):
    return a+b, a, a*b

x: Int

# Only retrieves the a*b return value from function foo
x = InvokeOutputs(foo, parms={"a": 1, "b": 2}, outputs=["output:result2"])

Associating APEX node IDs to a graph

If you have multiple graphs, you can use the special function SetGraph() to associate node IDs to a particular graph:

graph1: ApexGraphHandle = BindInput()
graph2 = ApexGraphHandle()

my_node: ApexNodeID = BindInput()

# Associate my_node with graph2
my_node.SetGraph(graph2)

Associate multiple node IDs to different graphs:

graph1: ApexGraphHandle = BindInput()
graph2 = ApexGraphHandle()

node_arr = ApexNodeIDArray()

# Append APEX node IDs to array
for i in range(4):
    node_arr.append(Value_ApexNodeID_())

# Associate node ID in node_arr[1] to graph2
x = node_arr[1]
x.SetGraph(graph2)

# Associate node ID in node_arr[2] to graph1
# Different way of calling SetGraph()
y = node_arr[2]
setGraph(y, graph1)

Special function arguments

The special function arguments listed below can be used to specify certain information on a node:

Argument

Type

Description

__name

String

The name of the node.

__color

Vector3

The color of the node.

__pos

Vector3

The position of the node in the graph.

__properties

Dict

The properties stored on the node.

__tags

StringArray

The tags stored on the node.

Example:

def abc(a: Vector3, b: Float):
    a = a * b
    b = b + 1.0
    return a, b

# Subnet node name is set to the function name
subnet_a = abc(a=(3.0, 3.0, 3.0), b=5.5)

# Special function arguments used to set the name and color of the subnet node
subnet_b = abc(a=(3.0, 3.0, 3.0), b=5.5, __name='test_b', __color=(1,0,0))
Create subnet nodes using special function arguments

KineFX

Overview

Preparing character elements

Rigging with APEX graphs

  • APEX graph basics

    Introduction to the APEX graph evaluation framework.

  • APEX graph debugger

    Inspect the values of an APEX graph’s ports within the APEX network view.

  • APEX Script basics for graph building

    An overview of APEX Script, a code interface for building APEX graphs.

  • Graphs for numerical operations

    Example graphs of numerical operations like adding two values, fetching multiple results, and retrieving information from geometry.

  • Graphs for viewport animation

    Example graphs of animate state functionality like creating controls and constraints, and defining joint hierarchies.

  • Graphs for deforming geometry

    Example of a SOP network and APEX graph for deforming a 3-joint tube geometry.

  • Graph metadata

    Information added to graph nodes and ports.

  • APEX path pattern

    A set of rules that allow you to filter and select elements within graphs, skeletons, geometry, and the character folder structure.

  • APEX graph nodes

    APEX nodes provide operations for building up the functionality of APEX graphs, which are used in KineFX to create character rigs and perform other geometry manipulation.

  • APEX updates for H22

    New and updated APEX graph nodes for Houdini 22.

Building rig graphs with APEX Script

Rigging with rig components

Animating in the viewport

  • Animation workflow

    Example networks of adding characters, props, characters, and animation to a scene.

  • Animating in LOPs

    Rig and animate characters and props in the context of a USD stage.

  • Working in the animate state

    Select and manipulate controls, define transform limits for controls, and add skin controls to a character.

  • Animate state menus and HUDs

    Menus, HUDs, toolbars, and options in the animate state.

  • Animate state hotkeys

    Hotkeys available in the animate state.

  • Posing

    Pose characters in the animation scene by using locators, copying and pasting controls, and mirroring poses.

  • Motion paths

    Visualize the motion of controls as curves in 3D space.

  • Constraints

    Create relationships between controls in the animate state.

  • Dynamic motion

    Add physically-accurate projectile motion to your animation in the animate state.

  • Ragdoll

    Add a ragdoll simulation to your animation in the animate state.

  • Full body IK

    Apply full body inverse kinematics to pose the character using high-level targets rather than manipulating individual joints.

  • Secondary motion

    Add physically-accurate effects like lag/overshoot, jiggle, and spring to your animation in the animate state.

  • Control selection sets

    A tree view of controls, selections, and selection sets for the animate state. Allows management of control selection and visibility.

  • Motion mixer

    Combine and edit the animation clips of multiple characters in a timeline-based view.

  • Character picker

    Create a 2D layout with simple buttons for selecting character controls in an animation scene.

  • Animation catalog

    Save, manage, and apply animations and single-frame poses to an animation scene.

  • Animation layers

    Create multiple layers of animation without affecting the original animation.

  • Animation toolbar

    A customizable toolbar consisting of simple slider tools that quickly apply modifications to animation controls and curves.

  • Animation bookmarks

    Frame markers that help organize and identify the different parts of your animation.

Customizing the animate state

SOP-based animation

  • Physics-based motion

    Add physically-accurate motion to your animation using the Projectile Motion and Pendulum Motion SOPs.

  • Ragdoll simulations

    Add a ragdoll simulation to your animation using the Ragdoll Solver SOP.

Deformation

  • Blend shapes

    Create blend shapes using blend shape SOP nodes.

Animation retargeting

Pre-H20

Panes

  • Motion mixer

    A timeline-based view of the animation clips and motion effects of multiple characters.

  • Character picker

    Create a 2D layout with simple buttons to select character controls in an animation scene.

  • Rig tree view

    A hierarchical view of character components, including packed character folders, KineFX rigs, and Object node rigs.

  • Animation editor

    View and edit animated parameters and their transitions between keyframes.

  • Geometry spreadsheet

    Displays details about the geometry selected in the network editor.

Appendix