Note to self on Python in Houdini.

Edit menu items of an existing combobox parm

import hou

node = hou.node('/obj/geo1/CTRL')
group = node.parmTemplateGroup()
template = group.find('theme')

theme_list = ['A', 'B', 'C']

group.replace('theme', template)

PET=”/Users/johan/Desktop/pet” HOUDINI_SCRIPT_PATH = $PET/scripts;@/scripts

and in the script dir

import sys

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
  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')

# mantra
mantra_driver = hou.node('/out').createNode('ifd')

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)


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"