Configure Houdini Operators with Event Scripts

Ah yes, the good old Geometry node in Houdini. What would we do without it? By default, when we place down a Geometry node, our little friend creates a File operator at the Geometry level. At first it’s cute. Sort of like when your cats knock crap off the shelves. So funny!

Scrambles Attacks
Scrambles Attacks

However, after a while it gets quite annoying. Drop a geo node, dive inside, delete File operator. Rinse and repeat. I appreciate the gesture but I can drop my own File node when I need it, thank you very much! Fortunately, in typical Houdini fashion, we are able to configure this behavior. One way we can accomplish this is by configuring operators in Houdini with Event Scripts.

Event scripts

Houdini can run scripts in response to certain events. For example, when Houdini first launches, it runs the 123.cmd script to configure the environment. It can also run the 456.cmd script for when you create or open a scene file. You can also have scripts that perform an action when an object is selected in the viewport. As you can imagine, event scripts are called when creating operators. This is very useful for customizing the behavior of built-in operators.

When you create certain operators, Houdini runs a corresponding script that performs various tasks. This may include preserving compatibility with older versions of Houdini, setting up some default parameters, or in our case, creating other operators i.e File operator.

The trick to getting this to work is setting up the correct directory structure and including the appropriately named script file that corresponds to the operator we are configuring. These script files are typically written in HScript and end with a .cmd extension. I like to think of them as Bash scripts.

Oh brother, do we need to know how to script? Not necessarily, but it does help. Otherwise you are going to have to test through trial and error. Which is a great way to learn by the way #protip.

Houdini already has all these operator scripts setup for its own customization. All you have to do is make a copy of the operator script in your user scripts directory.

The Setup

Houdini will search through the list of directories defined in the HOUDINI_SCRIPT_PATH environment variable. By default, it includes $HFS/houdini/scripts (for factory-installed scripts), $HSITE/scripts (for site-specific scripts), $JOB/scripts (for job-specific scripts), and $HOME/houdniversion/scripts (for each user’s scripts). If you have a modified HOUDINI_SCRIPT_PATH environment variable, you may need to make the necessary adjustments.

We are interested in the last path, that is, $HOME/houdniversion/scriptsScripts in this directory will override scripts in $JOBS, $HSITE, and $HFS. This is great because you can use this feature to replace factory-installed scripts—such as 123.cmd—with your own scripts and leave the factory-installed scripts intact. If you ever want to revert, all you have to do is delete the script in your user directory.

Since we want to modify the Geometry operator, what we need to do first is check that we have a scripts folder in our Houdini preferences directory, a.k.a HOUDINI_USER_PREF_DIR . If you don’t, you need to create it.

Scripts Folder Structure
Scripts Folder Structure

Next thing you want to do is navigate to $HFS. I’m showing you OS X paths since I work on a Mac but if you’re on a PC, you will need to do some hunting around. Easiest way is to echo out the value of $HFS or just type hconfig in your shell to get a list of the environment variables and corresponding paths. Even easier, on OS X, open $HFS directly.

open $HFS
Houdini $HFS
Houdini $HFS

If you go inside the scripts directory, you will see various operator directories in addition to the 123.cmd scripts I mentioned. You also have some scripts such as traverse.cmd and pickandcenter.cmd. These are callable by the way. The exact path is:

$HFS/Resources/houdini/scripts/obj/

You need to duplicate the same directory structure for the operators inside your user scripts directory. So it will be like the following:

scripts/op_type/op_internal_name.cmd

You can grab the internal operator name by just looking at the files within the scripts directory or by using the Operator Type Manager window.

Operator Type Manager
Operator Type Manager

Once you copy the geo.cmd script file over to your user directory and place it in its properly named operator type directory (obj), it should look like this:

Scripts Directory Structure
Scripts Directory Structure

The Script

Now for the final part to make it all work. Open the geo.cmd in your favorite text editor. I’m using Sublime here. I’m not going to go into the specifics of the language. I leave that up to the reader to research. All we’re going to do is delete some lines. Make sure you are working on the copy of the script. Once you open the file, you will see the following:

Houdini geo.cmd script
Houdini geo.cmd script

We are going to delete lines 10 through 16. Your file should look life the following now:

Houdini geo.cmd edited script
Houdini geo.cmd edited script

That’s it! Save your file and restart Houdini. Now if you place down a Geometry node and dive inside, the File operator is nowhere to be found. If you want the default behavior back, just remove the script. If its not working for you, make sure you have the directory structure and naming correct.

The question that may be circling in your mind right now is “Why not just save the Geometry node without the File node as a preset?” and you can certainly do that. The way presented is great if you wanted to do more advanced setups with your nodes.

Until next time Houdini friends!

Share:
990adjustments

990adjustments

I am a motion designer & developer based out of South Florida. When not designing or animating pixels, I wrangle some code. If all else fails, I watch Twilight Zone, I Love Lucy, or Three's Company reruns.