Python in Houdini


With the release of Houdini 9 the implementation of the Python scripting language has made the development and extension of Houdini far more accessible, easier and faster. H9 introduced HOM, the Houdini Object Model, which is an API [application programming interface] that allows for an ease of development not seen with the previous verbose HDK. In fact the HOM API allows for control of Houdini with the simplicity of the Python scripting language.

The reasons for Python's implementation lie in the language's ease and accessibility, for it's a loosely based object oriented language making it incredibly adaptable by creating new objects or modules for specific needs. The hou package is the top of a hierarchy of modules, functions, and classes that a central to the HOM.

Houdini uses an embedded Python interpreter and you can import various Python modules for your scripts; wx, a GUI toolkit; os, for operating system objects and so forth. Of course you can create your own modules and import those as well.

WHERE TO USE PYTHON

There are a number of ways to use Python within Houdini. In the Tool creation section we will use the shelf tool but there are others the Pyhton Shell, Tab tools and Python sops are some of the favourites. Scripting tools in Python really is the glue between the technology and the artist.

Python Shell

To use the Python Shell, just create a new pane and change it to a Python shell. A good way is to use alt+] to split the view pane top to bottom and then select Python Shell. From here you can do anything you want and it is the best place for prototyping code and searching through the hou module with the interactive help. You can use Node.asCode() too, to find out how exactly how specific nodes have been created. However type 2 + 2 and hit enter and you will see you can use it just as a calculator too if you wish.

Shelf/tab menu tools

I have already mentioned the shelf tools but you can make tab tools also by creating a New Operator Type. Then you can use your Python scripts specific to your networks.

You can use Python everywhere in Houdini and also link it outside by perhaps importing the os module for operating system tasks. Where Python is really powerful is in its cross platform capabilities; a python script will run the same on Windows, Linux, Unix and so forth just enhancing its reputation for flexibility. This felxibility makes Python the glue that can hold together a VFX pipeline.

For an in depth look into Python's implementation into Houdini the document Python in Houdini for Technical Directors (2007), available at the Side Effect's website, is a great resource for beginning to undestand the power of Python, with a great example of a script that can convert all absolute paths to paths relative to $HIP. I strongly recommend it.

With a quick introduction here to Python's usage we will expand upon the capabilities of Python
scripting as we move through the Tool Creation workflow in the next section.



back to top