git.lucas.co / hou-control
git clone https://git.lucas.co/hou-control.git

scripts/123.py (919B)

 1 from pathlib import Path
 2 import hou
 3 import json
 4 
 5 # This file runs when houdini is opened without a .hip file
 6 
 7 # Check/create st_data directory
 8 data_dir = Path(hou.getenv("HOUDINI_USER_PREF_DIR")) / "st_data"
 9 data_dir.mkdir(parents=True, exist_ok=True)
10 
11 # Check/create state.json file
12 state_file = data_dir / "state.json"
13 
14 if not state_file.exists():
15     defaults = {
16         "last_file": ""
17     }
18 
19     with open(state_file, 'w') as f:
20         json.dump(defaults, f, indent=4)
21 
22 else:
23     with open(state_file, 'r') as f:
24         loaded_state = json.load(f)
25         last_file = loaded_state['last_file']
26         if last_file != "":
27             choice = hou.ui.displayCustomConfirmation(
28                 text=f"Open last file {last_file}?",
29                 buttons=("Yes", "No"),
30                 suppress=hou.confirmType.NoConfirmType
31             )
32             if choice == 0:
33                 hou.hipFile.load(last_file)
34