Houdini tip | Open parameter path in file browser

Hello,
in this post I will show you a small convenience trick. It will help you with locating files in your OS file browser, opening images in Mplay or any other application like Djv_view, RV.., directly from Houdini parameter window.

reveal.png

UPDATE 1: Fixed RV script to open folder with whole sequence instead of just one frame
UPDATE 2: Added Photoshop menu item, updated RV, mentioned Sequence From File package
UPDATE 3: On Linux, when opening in File browser, I clear LD_LIBRARY_PATH environment variable which may cause bugs in some situations, fixed some mistakes.
UPDATE 4: Fixed a bug, where Mplay opening script would incorrectly expand $OS variable in file path.

In Houdini you can modify couple of UI menus. Luckily one of the menus which you can modify is the one you see after right-clicking on a node parameter.
Those menu modifications are quite handy and well-controllable.

To modify parameter menu, you can create PARMmenu.xml file and put it into your $HOUDINI_PATH. PARMmenu.xml already exists in your $HH folder (houdini_installation_folder/houdini) and has defined all the default items. What you can do is to either edit this file, or create a new complementary one.

To add Open in… menu items as seen in the screenshot, create an empty PARMmenu.xml file and put it into houdini folder in your home directory (Linux: ~/houdini16.5, Windows: C:\Users\Username\Documents\houdini16.5). You can also put it to another directory which is in your $HOUDINI_PATH variable, or you can specify $HOUDINI_MENU_PATH variable pointing to the folder containing your file.

Put the following file into PARMmenu.xml: 


<?xml version="1.0" encoding="UTF-8"?>
<menuDocument>
<menu>
<subMenu id="open_in">
<label>Open in…</label>
<insertBefore />
<context>
<expression>len(kwargs["parms"]) > 0 and kwargs["parms"][0].parmTemplate().type().name() == "String"</expression>
</context>
<scriptItem id="reveal_in_file_browser">
<label>File browser</label>
<scriptCode>
<![CDATA[
import os
import sys
import subprocess
path = kwargs["parms"][0].eval()
old_path = path
if path != "":
path = hou.expandString(path)
path = os.path.normpath(path)
path = os.path.dirname(path)
if os.path.exists(path):
if sys.platform == "linux2":
new_env = os.environ
new_env["LD_LIBRARY_PATH"] = ""
subprocess.Popen(["xdg-open", path], env=new_env)
if sys.platform == "win32":
subprocess.Popen(["explorer", path])
if sys.platform == "darwin":
subprocess.Popen(["open", path])
else:
print('Folder "{}" does not exist or you do not have permission to access it'.format(old_path))
]]>
</scriptCode>
</scriptItem>
<scriptItem id="reveal_in_mplay">
<label>Mplay</label>
<scriptCode>
<![CDATA[
import os
import sys
import subprocess
in_path = hou.pwd().path()
hou.cd(kwargs["parms"][0].node().path())
path = kwargs["parms"][0].unexpandedString()
if path != "":
path = path.replace("$F", "\$F")
path = path.replace("$T", "\$T")
path = path.replace("$SF", "\$SF")
path = os.path.normpath( hou.expandString(path) )
subprocess.Popen(["mplay", path])
hou.cd(in_path)
]]>
</scriptCode>
</scriptItem>
<scriptItem id="reveal_in_gplay">
<label>Gplay</label>
<scriptCode>
<![CDATA[
import os
import sys
import subprocess
path = kwargs["parms"][0].eval()
if path != "":
path = os.path.normpath(path)
subprocess.Popen(["gplay", path])
]]>
</scriptCode>
</scriptItem>
<scriptItem id="reveal_in_rv">
<label>RV</label>
<scriptCode>
<![CDATA[
import os
import sys
import subprocess
path = kwargs["parms"][0].eval()
if path != "":
path = os.path.normpath(path)
subprocess.Popen(["rv", path])
]]>
</scriptCode>
</scriptItem>
<scriptItem id="reveal_in_djv_view">
<label>Djv view</label>
<scriptCode>
<![CDATA[
import os
import sys
import subprocess
path = kwargs["parms"][0].eval()
if path != "":
path = os.path.normpath(path)
subprocess.Popen(["djv_view", path])
]]>
</scriptCode>
</scriptItem>
<scriptItem id="reveal_in_photoshop">
<label>Photoshop</label>
<scriptCode>
<![CDATA[
import os
import sys
import subprocess
path = kwargs["parms"][0].eval()
if path != "":
path = os.path.normpath(path)
subprocess.Popen(["Photoshop", path])
]]>
</scriptCode>
</scriptItem>
</subMenu>
</menu>
</menuDocument>

view raw

PARMmenu.xml

hosted with ❤ by GitHub

After that you can start a new Houdini session and after right-clicking on any string parameter you should see the menu 🙂

Feel free to add your favorite tools into the menu. Note that you need to have tools executables present in your system $PATH variable.

One note for RV: right now the menu item will open the current frame only, if you want to load the whole sequence, then enable  Sequence From File package in your RV settings.

The menu items can contain a script to be executed or can refer to external python file.
One of nice features is that you can set a context expression for your menu items controlling whether they are visible. This way I limited them for string parameters only.

You can find more information about modifying menus in the documentation and you can check $HH/PARMmenu.xml for good example of using it.

One note: I was experiencing Houdini crashes on Windows after setting a context expression directly on scriptItem. Setting it on subMenu worked fine (the bug should be fixed in Houdini 16.5.484).

Thanks for reading all the way down 🙂

Advertisement
Houdini tip | Open parameter path in file browser