Auto load and add $JOB and $HIP shelves

   1137   4   1
User Avatar
Member
477 posts
Joined: Aug. 2014
Offline
Let's say I have the following project hierarchy:

$JOB
├── assets
│   ├── first_asset
│   │   ├── first_asset.hiplc
│   │   └── toolbar
│   │   └── tools.shelf
│   └── second_asset
│   ├── second_asset.hiplc
│   └── toolbar
│   └── tools.shelf
└── toolbar
└── tools.shelf

What's the optimal way of loading shelf tools residing in $JOB hierarchy, so that:
- $JOB/toolbar/tools.shelfis loaded automatically whenever I open any .hip file that resides inside $JOB,
- $HIP/toolbar/tools.shelfis loaded automatically whenever I open a .hip file from $JOB hierarchy?

Basically, I'd like Houdini to load $JOB/toolbar/toolbar/tools.shelffor any of $JOB's .hipfiles that I open, and for each one of those .hipfiles from $JOB, I want Houdini to load their corresponding tools from $HIP/toolbardirectory.

Additionally, I'd like to have those toolbars automatically added as shelf tabs whenever I open an existing scene file. I always found that to be somewhat inconsistent, as sometimes a shelf that I added before closing Houdini is reloaded after reopening the scene, but sometimes it simply isn't, and I have to add it manually.

Anyway, do I need to define the described behavior in scripts/456.pyfile, or perhaps there's a more streamlined way of achieving this goal?
Edited by ajz3d - March 6, 2023 18:23:47
User Avatar
Member
7802 posts
Joined: Sept. 2011
Offline
The way I've seen it done in a studio pipeline is for the houdini launcher script to add the current shot's houdini tool folder to the HOUDINI_PATH and let Houdini handle the rest.
User Avatar
Member
477 posts
Joined: Aug. 2014
Offline
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/toolbaror $HIP/toolbarpresent.

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 toolbardirectories, 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.
Edited by ajz3d - March 8, 2023 18:16:45

Attachments:
shelf_dock.png (12.3 KB)

User Avatar
Member
7802 posts
Joined: Sept. 2011
Offline
ajz3d
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?

Modifying your shelves saves it to your user prefs default.shelf. I'd highly recommend against trying to script shelves. It removes user agency by writing over their personal preferences without consent.
User Avatar
Member
477 posts
Joined: Aug. 2014
Offline
jsmack
I'd highly recommend against trying to script shelves. It removes user agency by writing over their personal preferences without consent.

Thanks for the warning.

From what I understand, each shelf has its own path (Shelf.filePath()), so shelves loaded by the script, once saved again, should be written to their existing paths, and not to $HOUDINI_USER_PREF_DIR. The only danger I can think of, is that when I manually attempt to add a new tool to one of those shelves, by default Houdini sets the default path to $HOUDINI_USER_PREF_DIR/toolbar/default.shelf, so I need to be careful and manually change it to the existing shelf file from either $JOB or $HIP. Is this what you mean, or are there more dangers of overwriting user config to be aware of?

I also tried the method that you described in your first post. As I understand it, it's about starting Houdini with predefined $HOUDINI_PATH envar which has $JOB and $HIP appended to it, ergo:
HOUDINI_PATH=$HOUDINI_PATH:/opt/hfs19.5:/path/to/job:/path/to/hip houdini hip_file

(Note that I had add path to /opt/hfs19.5or otherwise Houdini wouldn't start).

I'm not sure why, but Houdini launched with this command doesn't load any of the shelves from $JOB/toolbaror $HIP/toolbar, even though $JOB and $HIP are both in $HOUDINI_PATH which I can confirm by running hou.text.expandString('$HOUDINI_PATH'). I must be doing something wrong.

That aside, I have to say that the thought of having to maintain separate shell scripts or launchers for opening hip files fills me with a great dose of dread, and to be honest, I'd prefer a more dynamic, or should I say — automatic solution, which would not rely on hardcoded paths, and this is the main reason behind my experiments with 456.py, however dangerous they may be.

This is getting more complicated than I initially expected.
Edited by ajz3d - March 9, 2023 15:42:41
  • Quick Links