Custom Houdini Right Click Menues
I use a good number of installed packages, and I've always wondered how the custom right click menu's for the packages worked. After some amount of trial and error, I was able to figure out how add my own menus. In this tutorial we'll be creating a PARMMenu.xml
, which is the right click window that appears when right-clicking on a parameter.
First we need to make our package. I'll create a master folder, WebbLib
and create a scripts
folder and PARMMenu.xml
file inside of that:
- WebbLib
- scripts
- PARMMenu.xml
I then added the following WebbLib.json to my houdini packages folder - C:\Users\Primary User\Documents\houdini19.0, creating an environment variable WEBB_HOU
that with the path to my WebbLib folder:
{
"env": [
{
"WEBB_HOU": "C:\Users\Primary User\Desktop\LabsInstall\WebbLib"
},
],
"path": "$WEBB_HOU"
}
Here's the xml for my PARMMenu.xml:
<?xml version="1.0" encoding="UTF-8"?>
<menuDocument>
<menu>
<subMenu id="Webb">
<label>Webb</label>
<insertBefore />
<scriptItem id="Say Hello">
<label>Say Hello</label>
<scriptCode><![CDATA[
print("hello")
]]></scriptCode>
</scriptItem>
</subMenu>
</menu>
</menuDocument>
It's pretty painful to write actual python in the menu's XML file. A better practice is to write your code in your packages scripts
folder, then import
it into a scriptCode
tag. I created a directory webb
within my scripts
folder, then created a say_hello.py
script. Our function main
will receive a kwargs
argument generated by our right click. In this case, kwargs has information about our right click action, like what modifier keys were pressed when performing the right click, as well as the parameter we clicked on.
- WebbLib
- scripts
- webb
- say_hello.py
- PARMMenu.xml
#say_hello.py
def main(kwargs):
print(kwargs)
print("hello")
Then we import our say_hello
script into our menu:
<?xml version="1.0" encoding="UTF-8"?>
<menuDocument>
<menu>
<subMenu id="Webb">
<label>Webb</label>
<insertBefore />
<scriptItem id="Say Hello">
<label>Say Hello</label>
<scriptCode><![CDATA[
import webb.say_hello
webb.say_hello.main(kwargs)
]]></scriptCode>
</scriptItem>
</subMenu>
</menu>
</menuDocument>
Unfortunatley, as of 19.5 the only way to refresh our menu is to restart Houdini. So I'll usually do as much of the python development in a "dummy" shelf tool as possible.
I've included the code to reproduce this in the repo.