Thanks for the feedback @jsmack. After contemplating on the task, I decided to handle the process of dynamically loading shelves from within
456.py
:
#!/bin/python3
import hou
import os
from pathlib import Path, PurePath
toolbar_dir = 'toolbar'
job_path = hou.text.expandString('$JOB')
hip_path = hou.text.expandString('$HIP')
job_toolbar = PurePath(job_path, toolbar_dir, 'toolbar.shelf')
hip_toolbar = PurePath(hip_path, toolbar_dir, 'toolbar.shelf')
if Path(job_toolbar).exists():
hou.shelves.loadFile(str(job_toolbar))
if Path(hip_toolbar).exists():
hou.shelves.loadFile(str(hip_toolbar))
This will make those shelves available in the shelf dock's
+⟶Shelves list.
There is however a strange issue that I noticed. Houdini behaves funnily when I open a file with this script present. At first, it doesn't add those shelves to the dock, so I need to toggle them in the Shelves menu. This is OK, I guess, because the documentation doesn't state anywhere that when using
loadFile()
shelves will be added to the shelf dock. But then, if I close Houdini instance, even WITHOUT saving the scene file, when I reopen the program next time by loading the same hip file, Houdini starts with those shelves already added to the dock(!) and with a warning that the program "cannot find the definition of the shelf 'shelf_name'" (screenshot). It complains about it, even though tools from those shelves do seem to work properly... or at least clicking tool buttons works, because in my test $JOB/$HIP shelves I haven't created any scripts for them yet.
This message disappears if I remove those shelves from the dock and add them again by picking them from the shelves list. But it keeps reappearing each time I open a file with toolbars in either
$JOB/toolbar
or
$HIP/toolbar
present.
Launching Houdini without loading a scene removes those shelves from the dock. If I then load a scene which has them in $JOB or $HIP
toolbar
directories, those shelves are gone from the dock too. At this point they can of course be re-added from the shelf list again.
That's a really weird behavior, if you ask me. Where exactly does Houdini store information about shelves loaded by the program and added to the dock? How is it possible that it remembers what shelves were loaded even though I haven't saved the scene or saved changes done to the current desktop preset?
For the time being, I perceive this strange behavior as a bug.
This aside, the only thing left for me to figure out is how to automatically add loaded shelves to the shelf dock. I'm currently browsing the docs, but I don't see any function or method that would let me do so. It's already very late here, so perhaps I'm just tired.