Houdini 16.5 Python Scripting HOM Cookbook

HOM cookbook Open and inspect a scene file

On this page


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.



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

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

HOM Cookbook