Houdini 20.5

hapi package

Python wrapper of HAPI API

On this page

The hapi package contains the classes and functions for the Python wrapping of the Houdini Engine C API

Tip

When writing an engine integration it can be very useful to connect to a live session of interactive Houdini instead of HARS. This can be done with Houdini Engine SessionSync

Tip

The Houdini Engine C API documentation can be useful even when using the Python API because the same concepts and functions apply.

Getting Started

To...Do this

Create a Session

A session is an instance of the HARS executable, which is a complete headless Houdini. You can automatically start HARS and then attach to it.

import hapi
options = hapi.ThriftServerOptions()
process_id = hapi.startThriftSocketServer(options, 9090, "./my_log_file.txt")

session_info = hapi.SessionInfo()
session = hapi.createThriftSocketSession('localhost', 9090, session_info)

Attach to a Session

A session is an instance of the HARS executable, which is a complete headless Houdini. It can also be a running a Houdini instance with SessionSync active. You can attach to the session using a named pipe (e.g. /tmp/hapi) or a TCP socket connection (e.g. localhost:9090).

import hapi
session_info = hapi.SessionInfo()
session = hapi.createThriftSocketSession('localhost', 9090, session_info)

cook_options = hapi.CookOptions()
hapi.initialize(session, cook_options)

Load an HDA

If the HDA file is accessible to the server you can load it with hapi.loadAssetLibraryFromFile. If the HDA is only accessible to the client, you can send it as bytes with hapi.loadAssetLibraryFromMemory.

# Read myhda.hda into memory so we can send it over
hda_bytes = open('/tmp/myhda.hda', 'rb').read()
lib_id = hapi.loadAssetLibraryFromMemory(session, hda_bytes,
    len(hda_bytes), True)

Create a Node

# Assuming we have a loaded an asset which defines a SOP type `MyType`
node_id = hapi.createNode(session, -1, 'Sop/MyType')

# Get a hapi.NodeInfo for the new node
node_info = hapi.getNodeInfo(session, node_id)

# Getting a string is a two step process
str_len = hapi.getStringBufLength(session, node_info.nameSH)
node_name = hapi.getString(session, node_info.nameSH, str_len)

print('Created {}'.format(node_name))

Save scene data to file

It can be very useful for users to save out a hip file of the scene when debugging problems.

hapi.saveHIPFile(session, '/tmp/debug.hip')
hapi.saveGeoToFile(session, node_id, '/tmp/debugGeo.bgeo.sc')

Next Steps

API Reference

Animation

Assets

Attributes

Caching

classes

Curves

Environment

functions

Geometry

GeometryGetters

GeometrySetters

HeightFields

HipFiles

InputCurves

Materials

Nodes

Objects

Parms

PDG

Presets

Sessions

SessionSync

Status

Strings

Time

types

Utility

Volumes

Houdini 20.5

Getting started

Using Houdini

  • Geometry

    How Houdini represents geometry and how to create and edit it.

  • Copying and instancing

    How to use copies (real geometry) and instances (loaded or created at render time).

  • Animation

    How to create and keyframe animation in Houdini.

  • Digital assets

    Digital assets let you create reusable nodes and tools from existing networks.

  • Import and export

    How to get scene, object, and other data in and out of Houdini.

  • MPlay viewer

    Using Houdini’s stand-alone image viewer.

Character FX

  • Character

    How to rig and animate characters in Houdini.

  • Crowd simulations

    How to create and simulate crowds of characters in Houdini.

  • Muscles and tissue

    How to create and simulate muscles, tissue, and skin in Houdini.

  • Hair and fur

    How to create, style, and add dynamics to hair and fur.

  • Feathers

    How to create highly realistic and detailed feathers for your characters.

Dynamics

  • Dynamics

    How to use Houdini’s dynamics networks to create simulations.

  • Vellum

    Vellum uses a Position Based Dynamics approach to cloth, hair, grains, fluids, and softbody objects.

  • Pyro

    How to simulate smoke, fire, and explosions.

  • Fluids

    How to set up fluid and ocean simulations.

  • Oceans and water surfaces

    How to set up ocean and water surface simulations.

  • MPM

    How to simulate different types of solid materials (such as snow, soil, mud, concrete, metal, jello, rubber, water, honey, and sand).

  • Destruction

    How to break different types of materials.

  • Grains

    How to simulate grainy materials (such as sand).

  • Particles

    How to create particle simulations.

  • Finite elements

    How to create and simulate deformable objects

Pipeline

  • Executing tasks with PDG/TOPs

    How to define dependencies and schedule tasks using TOP networks.

  • HQueue

    HQueue is Houdini’s free distributed job scheduling system.

  • Houdini Engine

    Documents the Houdini Engine C, Python APIs, and Houdini Engine plugins

  • Machine Learning

    Houdini provides a platform for machine learning which supports synthetic data generation, preprocessing, training models, exporting trained models, and deploying trained models

Nodes

  • OBJ - Object nodes

    Object nodes represent objects in the scene, such as character parts, geometry objects, lights, cameras, and so on.

  • SOP - Geometry nodes

    Geometry nodes live inside Geo objects and generate geometry.

  • DOP - Dynamics nodes

    Dynamics nodes set up the conditions and rules for dynamics simulations.

  • VOP - Shader nodes

    VOP nodes let you define a program (such as a shader) by connecting nodes together. Houdini then compiles the node network into executable VEX code.

  • LOP - USD nodes

    LOP nodes generate USD describing characters, props, lighting, and rendering.

  • ROP - Render nodes

    Render nodes either render the scene or set up render dependency networks.

  • CHOP - Channel nodes

    Channel nodes create, filter, and manipulate channel data.

  • COP - Copernicus nodes

    COP nodes provide real-time image manipulation within a 3D space.

  • TOP - Task nodes

    TOP nodes define a workflow where data is fed into the network, turned into work items and manipulated by different nodes. Many nodes represent external processes that can be run on the local machine or a server farm.

  • APEX - APEX 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.

Scene building, Karma rendering, Image processing

  • Solaris and Karma

    Solaris is the umbrella name for Houdini’s scene building, look development, and Karma rendering tools based on the Universal Scene Description (USD) framework.

  • Copernicus

    Houdini’s 2D and 3D GPU image processing framework.

  • Compositing

    Houdini’s compositing networks let you create and manipulate images such as renders.

Mantra rendering and shading

Reference

  • Menus

    Explains each of the items in the main menus.

  • Viewers

    Viewer pane types.

  • Panes

    Documents the options in various panes.

  • Windows

    Documents the options in various user interface windows.

  • Stand-alone utilities

    Houdini includes a large number of useful command-line utility programs.

  • APIs

    Lists all the reference documentation for the ways you can program Houdini.

  • Python scripting

    How to script Houdini using Python and the Houdini Object Model.

  • Expression functions

    Expression functions let you compute the value of parameters.

  • HScript commands

    HScript is Houdini’s legacy scripting language.

  • VEX

    VEX is a high-performance expression language used in many places in Houdini, such as writing shaders.

  • Properties

    Properties let you set up flexible and powerful hierarchies of rendering, shading, lighting, and camera parameters.

  • Galleries

    Pre-made materials included with Houdini.

  • Houdini packages

    How to write and combine multiple environment variable definition files for different plug-ins, tools, and add-ons.

  • hwebserver

    Functions and classes for running a web server inside a graphical or non-graphical Houdini session.