SideFX Houdini customization package
git clone https://git.lucas.co/hou-control.git
scripts/456.py (1.1K)
1 from pathlib import Path
2 import hou
3 import json
4 from hc import HCSession
5
6 # This file runs when a .hip file is loaded
7
8 current_file = hou.hipFile.path()
9 state_file = Path(hou.getenv("HOUDINI_USER_PREF_DIR")) / "st_data" / "state.json"
10
11 # Houdini reports $HOME/untitled.hip for a scene that has never been saved.
12 # Recording that phantom path made the next startup offer to open a file that
13 # was never written, which raised hou.OperationFailed in 123.py. Only remember
14 # a scene that actually exists on disk.
15 if Path(current_file).is_file():
16 state_file.parent.mkdir(parents=True, exist_ok=True)
17 updates = {"last_file": current_file}
18 with open(state_file, 'w') as f:
19 json.dump(updates, f, indent=4)
20
21 HCSession().updateNodeColors()
22 # The hcnetcursor state is keyed by pane and network path, so an editor
23 # showing the same path as before the load keeps the old scene's cursor, and
24 # a fresh one is only created lazily while drawing. Neither highlights what
25 # is under it until a cursor key runs the selection sync; do that now.
26 HCSession().resetHcnetcursorsDeferred()