+ HOUDINI PYTHON

Note to self on Python in Houdini.

Add custom script dir

I am quite new to Houdini, so there might be better ways/best practices to add a custom directory to house your python scripts, but this has worked for me.

  1. Open up the houdini.env file.
    • On a mac it is found here ~/Library/Preferences/houdini/X.X/houdini.env
    • docs config_env
  2. Add the path to your dir.
    • From the docs: To add a directory “/mypath” to the default path for a variable, use “/mypath;&;”. This will search “/mypath” path first, then the directories on the default path.
      HOUDINI_PATH = "/your/custom/path/Houdini;$HOUDINI_PATH;&;"
      
  3. Create a dir called “scripts” that is inside the dir we just added to the env file.

  4. In the “scripts” dir, create a python file and called 123.py and append a path to where ever you want to keep your scripts. This can be a dir that is inside the scripts dir or elsewhere.
    import sys
    sys.path.append('/your/custom/path/houdini/scripts')
    
  5. Now this path will be on your python path when you launch Houdini, so add your python packages or modules as per usual. Use the python shell in Houdini and sys.path verify.

Create a python shelf tool

# camera
render_cam = hou.node('/obj').createNode('cam')
render_cam.setName('render_cam_HD')
render_cam.parm('resx').set(1920)
render_cam.parm('resy').set(1080)

# mantra
mantra_driver = hou.node('/out').createNode('ifd')
mantra_driver.setName('mantra_render_HD')
mantra_driver.parm('camera').set('/out/render_cam_HD')
mantra_driver.parm('vm_renderengine').set('pbrraytrace')

Run a python script from a node

Create a null and edit the param interface. To make it less cluttered we can hide copy and cache input. Then we add a string and a button. We give the string parameter the name code and make it a multiline string and set the language to Python. On the button we set the callback script to Python and type the following expression in the callback script line edit:

exec hou.node('.').parm('code').eval()

If we click the button the python code that we eneterd in the string parameter text input filed will be executed.

Custom path to HDA

HDA - Houdini Digital Asset

To add a custom path to a directory containing HDA we can use the houdini.env file. On a Mac we find the env file here: (replace with current version)

Library/Preferences/houdini/16.0/

Then we add the the path to the disired directory. We also need to make sure that we do not overwrite the internal path to otl.

HOUDINI_OTLSCAN_PATH = "/your/path/hda;&;$HFS/houdini/otl"