Tuesday, August 5, 2014

Powerful method hou.hipFile

Just a quick arcticle to speak a bit about the not well known but powerful python class hou.hipFile.
It allows you to have access, open, edit, save, merge hip file from python. For instance, you could drive Houdini from an external python tool without opening Houdini at all.

You have access then to all python methode of the Houdini module. You can export geos, do mantra rendering, create / manipulate object and otls etc.

For instance the code bellow, we will open the hip file "houhipfile.hip" and export the geo which is in that file tanks to a rop_output node, (warning this does not work with houdini apprentice):

# Here we setup the path to the HIP file as well as where you want to export the bgeo file.
PATH = r"H:/houhipfile.hip"
OUTPUT_GEO = r"H:/teapot.bgeo"

# Here we load the hip file.

# Then we fetch the rop output node
ropNode = hou.node("obj/outputGeo/rop_output")

# We change the Ouput path parameter

# We do the render ( exporting the geo )

# And finally we clean the current houdini session

This could be launched from any python tool, with a nice UI in PyQt for instance.

Instead of opening a hip file, you could of course create nodes from scratch:

root = hou.node("/obj")
geo = root.createNode("geo")
and then you have access to the geo node's parms, etc.

More infos here => hou.hipFile class help
And you can download the hip file as example here