Houdini 22.0 Character KineFX

APEX Script basics for graph building

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

On this page

Overview

APEX Script is a code interface for building APEX graphs. It uses a Python-like syntax to generate graphs that represents the code logic. APEX Script snippets can be written in the APEX Script SOP, which can take in inputs, execute the code snippet, and output the results. The APEX AutoRig Component SOP also provides an interface for writing APEX Script snippets.

APEX Script snippets have a direct representation as an APEX graph. As you type APEX Script code, you can see its graph representation being generated in the APEX network view:

APEX Script can be used as a tool to build new graphs, modify existing graphs, and retrieve graph data. See the following pages for more information:

  • Working with graphs shows how to use APEX Script to access and manipulate graph elements, add graph logic directly into another graph, and invoke other graphs from within a graph.

  • Create your own functions in APEX Script or use the built-in APEX functions within your code snippet.

  • Use APEX Script to create and customize interfaces for your graphs.

  • The APEX Script language reference describes the syntax and language elements of APEX Script, including the provided types, operations, and statements.

Viewing APEX Script as a graph

In APEX Script, BindInput() is a special function that defines the inputs to a graph. It creates a parms node with ports that represent the graph inputs. The BindOutput() function defines the graph outputs and creates an output node with ports that represent the values that are output from the graph.

In this example, we write an APEX Script snippet that takes a value as an input, and outputs the same value:

  1. Put the following snippet in an APEX Script SOP, Snippet parameter:

    a = BindInput(3.5)
    
    BindOutput(a)
    
  2. To see the APEX Script snippet represented as a graph, open up the APEX network view. At the top of a pane, click the New Tab icon and select New Pane Tab Type ▸ Animation ▸ APEX Network View.

  3. On the APEX Script SOP, Visualizer section, set Show to Component Script.

    APEX Script code represented as a graph

View graph inputs

To view the graph input values:

  1. In the geometry spreadsheet, beside the node name, select Apex Script Graph from the drop-down menu.

    or

    Connect the 2nd output (APEX Script Graph output) of the APEX Script SOP to a Null SOP, and select the Null SOP.

  2. In the geometry spreadsheet, click Detail on the top toolbar. The input parameters are stored in the parms detail attribute on the graph.

If you click the Reload Setup Parms button in the APEX Script SOP, the graph inputs will appear in the parameter editor as parameters that you can adjust.

View graph outputs

To view the graph output values:

  1. By default, the first entry of Output Dictionary Bindings on the APEX Script SOP, Invocation section is filled out with the following:

    • Apex Outputs Group is the set to output. This is the name of the output node in the graph.

    • Output Attrib is set to parms. This is the name of the output to store in a dictionary format. We can set this to any name.

  2. In the geometry spreadsheet, beside the node name, select Invoked from the drop-down menu.

  3. Click Detail on the top toolbar. The graph outputs are stored in the dictionary specified in Output Attrib.

Building a new graph

In this example, we use APEX Script to create a new graph that contains a single TransformObject node:

  1. In an APEX Script SOP, add the following code to the Snippet parameter:

    # Initialize a graph
    graph = ApexGraphHandle()
    
    # Add a TransformObject node to the new graph
    graph.addNode('test_a', 'TransformObject')
    
    # Write out the graph as geometry
    geo = graph.saveToGeometry()
    BindOutput(geo)
    
  2. See the graph representation of the APEX Script snippet in the APEX network view. On the APEX Script SOP, Visualizer section, set Show to Component Script:

    APEX Script as a graph
  3. To output the graph as a geometry, set Bind Output Geometry to <output_node>:<output_port>. In our case, it is output:geo.

  4. To see the new graph created by the APEX Script snippet:

    • On the APEX Script SOP, Visualizer section, set Show to Output 1.

      or

    • Connect the 1st output of the APEX Script SOP to a Null SOP, and select the Null SOP.

      Graph created by APEX Script

Modifying an existing graph

In this example, we use APEX Script to add a TransformObject node to an existing graph:

  1. On an APEX Graph SOP, create a graph that contains only an input and output node:

    Original graph
  2. Connect the graph as an input to an APEX Script SOP:

    Update original graph
  3. In the APEX Script SOP, use the predefined headers to automatically add the APEX Script commands that take in and modify an input graph:

    • Turn on the Header parameter.

    • In the Header section, set Template to Graph, which adds the following code to the beginning and end of your APEX Script snippet:

  4. Specify the input to the APEX Script SOP. In the Invocation section, under Input1 Bindings, turn on Bind To Geometry Parameter and set the parameter to geo - geo is the graph geometry that is input to the APEX Script SOP, specified in the header from the previous step.

  5. To output the updated graph, set Bind Output Geometry to output:geo.

  6. The APEX Script SOP now takes in the input graph and outputs it unchanged. To see the graph that is output by the APEX Script SOP:

    • On the APEX Script SOP, Visualizer section, set Show to Output 1.

      or

    • Connect the 1st output of the APEX Script SOP to a Null SOP, and select the Null SOP.

  7. To add a TransformObject node to the input graph, put the following code in the Snippet parameter:

    graph.addNode('test_a', 'TransformObject')
    
    Updated graph

How-to

To...Do this

Make code changes take effect

After making changes to the code snippet, press ⌃ Ctrl + Enter.

View the graph nodes that are associated with the APEX Script line number

  1. Set Show to Component Script.

  2. Turn on the Inspect Line parameter. The graph nodes that are associated with the APEX Script line number are colored red in the APEX network view.

Lay out the nodes in a graph

Add graph.layout() to the APEX Script snippet.

Comment or uncomment a block of code

Select a block of code and press ⌃ Ctrl + /.

Change the code snippet font size

Click inside the Snippet parameter and press ⌃ Ctrl + + or ⌃ Ctrl + -.

Convert a graph to APEX Script code

See converting graphs to APEX Script.

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