Houdini 20.5 Python scripting HOM Cookbook

HOM cookbook Open and inspect a scene file

On this page

Overview

This example shows how to load a hip file from a Python shell and inspect its contents. This example loops through all the object in /obj and prints out the positions of each of the points in the object.

Implementation

hou.hipFile.load("file_to_load.hip")

for object in hou.node("/obj").children():
    print "Points in", object.path()
    for point in object.displayNode().geometry().points():
        print point.position()
    print

Running outside out Houdini

You can run this example outside of Houdini or Hython (that is, in a standard Python environment) if you first add hou to the Python path and import it (note that this will still use a Houdini license).

import sys, os

# Adjust sys.path so it contains $HFS/houdini/pythonX.Xlibs.  Then we can
# safely import the hou module.  Importing this module will bring a Houdini
# session into the Python interpreter.
sys.path.append(
    os.environ['HFS'] + "/houdini/python%d.%dlibs" % sys.version_info[:2]
)
import hou

If you want to use hou as part of a larger general Python application, and you want to take up a license for the minimum time possible, you can release the license when you're done with it using hou.releaseLicense():

# Release the Houdini Batch license. If this script accesses the hou
# module again it will reacquire the license automatically.
hou.releaseLicense()

HOM Cookbook