git clone https://git.lucas.co/hou-control.git
listeners: update listeners
python3.11libs/nodegraphhooks.py | 50 +++++++++++++++++++---------------------
python3.11libs/uiready.py | 8 +++----
radialmenu/hceditor.radialmenu | 2 +-
radialmenu/hcviewer.radialmenu | 2 +-
scripts/123.py | 49 +++++++++++++++++++++------------------
scripts/456.py | 14 +++++++++++
scripts/OnCreated.py | 13 +++++++++++
7 files changed, 84 insertions(+), 54 deletions(-)
diff --git a/python3.11libs/nodegraphhooks.py b/python3.11libs/nodegraphhooks.py
index 79580a4..d64c892 100755
--- a/python3.11libs/nodegraphhooks.py
+++ b/python3.11libs/nodegraphhooks.py
@@ -1,15 +1,15 @@
import hou
from canvaseventtypes import *
import nodegraphdisplay as display
-from hclib import HCNetworkEditor
+from hc import Session, NetworkEditor
# import nodegraphview as view
def createEventHandler(uievent, pending_actions):
if isinstance(uievent, ContextEvent):
- # hceditor = HCNetworkEditor(uievent.editor)
- # hceditor.showPathMessage()
+ # editor = NetworkEditor(uievent.editor)
+ # editor.showPathMessage()
# return None, True
return None, False
@@ -18,30 +18,28 @@ def createEventHandler(uievent, pending_actions):
elif isinstance(uievent, KeyboardEvent) and \
uievent.eventtype == 'keyhit':
- hceditor = HCNetworkEditor(uievent.editor)
+ editor = NetworkEditor(uievent.editor)
+ session = Session()
keymap = {
- ## Zoom
- '=': lambda: hceditor.zoom('in'),
- '-': lambda: hceditor.zoom('out'),
- ## Move view
- 'K': lambda: hceditor.translateView('up'),
- 'J': lambda: hceditor.translateView('down'),
- 'H': lambda: hceditor.translateView('left'),
- 'L': lambda: hceditor.translateView('right'),
- ## Move node
- 'Ctrl+K': lambda: hceditor.translateNodes('up'),
- 'Ctrl+J': lambda: hceditor.translateNodes('down'),
- 'Ctrl+H': lambda: hceditor.translateNodes('left'),
- 'Ctrl+L': lambda: hceditor.translateNodes('right'),
- ## Organize
- 'Ctrl+Shift+A': hceditor.arrangeNodes,
- 'Shift+D': hceditor.addDot,
- ## Grid
- 'Shift+G': hceditor.toggleGridMode,
- ## Update mode
- 'M': hceditor.toggleUpdateMode,
- ## Radial menu
- 'C': hceditor.showRadialMenu
+ # Zoom
+ '=': lambda: editor.zoom('in'),
+ '-': lambda: editor.zoom('out'),
+ # Move view
+ 'K': lambda: editor.translateView('up'),
+ 'J': lambda: editor.translateView('down'),
+ 'H': lambda: editor.translateView('left'),
+ 'L': lambda: editor.translateView('right'),
+ # Move node
+ 'Ctrl+K': lambda: editor.translateNodes('up'),
+ 'Ctrl+J': lambda: editor.translateNodes('down'),
+ 'Ctrl+H': lambda: editor.translateNodes('left'),
+ 'Ctrl+L': lambda: editor.translateNodes('right'),
+ # Organize
+ 'Ctrl+Shift+A': editor.arrangeNodes,
+ # Grid
+ 'Shift+G': editor.toggleGridMode,
+ # Selection
+ 'Ctrl+D': editor.pwd().deselectAll
}
key = uievent.key
diff --git a/python3.11libs/uiready.py b/python3.11libs/uiready.py
index 19523c0..4f397d5 100644
--- a/python3.11libs/uiready.py
+++ b/python3.11libs/uiready.py
@@ -1,11 +1,11 @@
import hou
-from hclib import HCGlobal
+from hc import Session
from PySide6.QtCore import Qt
-hcglobal = HCGlobal()
+session = Session()
-hcglobal.reloadHotkeys()
-hcglobal.toggleStowbars()
+session.reloadHotkeys()
+session.toggleStowbars()
## Set network grid points to on
# networkeditors = desktop.getNetworkEditors()
diff --git a/radialmenu/hceditor.radialmenu b/radialmenu/hceditor.radialmenu
index 7356245..63f1e52 100644
--- a/radialmenu/hceditor.radialmenu
+++ b/radialmenu/hceditor.radialmenu
@@ -5,5 +5,5 @@
"pane":"network",
"label":"HC Editor Radial Menu",
"type":"script_submenu",
- "script":"from hclib import hcradialutils as hcru\n\nmenu = hcru.editorRadialMain(**kwargs)\nradialmenu.setRadialMenu(menu)"
+ "script":"from hc import radialutils as ru\n\nmenu = ru.editorRadialMain(**kwargs)\nradialmenu.setRadialMenu(menu)"
}
diff --git a/radialmenu/hcviewer.radialmenu b/radialmenu/hcviewer.radialmenu
index c2eac64..7590d63 100644
--- a/radialmenu/hcviewer.radialmenu
+++ b/radialmenu/hcviewer.radialmenu
@@ -5,5 +5,5 @@
"pane":"scene",
"label":"HC Viewer Radial Menu",
"type":"script_submenu",
- "script":"from hclib import hcradialutils as hcru\n\nmenu = hcru.viewerRadialMain(**kwargs)\nradialmenu.setRadialMenu(menu)"
+ "script":"from hc import radialutils as ru\n\nmenu = ru.viewerRadialMain(**kwargs)\nradialmenu.setRadialMenu(menu)"
}
diff --git a/scripts/123.py b/scripts/123.py
index 27894a0..901f57e 100644
--- a/scripts/123.py
+++ b/scripts/123.py
@@ -1,29 +1,34 @@
-# import pathlib
+from pathlib import Path
+import hou
+import json
-# print("--BEGIN 123.py--")
+# This file runs when houdini is opened without a .hip file
-# enable_recent_menu = 0
+# Check/create st_data directory
+data_dir = Path(hou.getenv("HOUDINI_USER_PREF_DIR")) / "st_data"
+data_dir.mkdir(parents=True, exist_ok=True)
-# if enable_recent_menu == 1:
-# path_raw = "~/src/hou-ctl/recent_paths"
-# path = pathlib.PosixPath(path_raw)
-# path = path.expanduser()
+# Check/create state.json file
+state_file = data_dir / "state.json"
-# if not path.is_file():
-# path.touch()
+if not state_file.exists():
+ defaults = {
+ "last_file": ""
+ }
-# choices_raw = path.read_text()
-# choice_arr = choices_raw.split("\n")
-# i = hou.ui.selectFromList(
-# choices=choice_arr,
-# exclusive=True,
-# message="Recent Files",
-# column_header="Path"
-# )
+ with open(state_file, 'w') as f:
+ json.dump(defaults, f, indent=4)
-# # on accept
-# if len(i) > 0:
-# choice = choice_arr[i[0]]
-# hou.hipFile.load(choice)
+else:
+ with open(state_file, 'r') as f:
+ loaded_state = json.load(f)
+ last_file = loaded_state['last_file']
+ if last_file != "":
+ choice = hou.ui.displayCustomConfirmation(
+ text=f"Open last file {last_file}?",
+ buttons=("Yes", "No"),
+ suppress=hou.confirmType.NoConfirmType
+ )
+ if choice == 0:
+ hou.hipFile.load(last_file)
-# print("--END 123.py--")
diff --git a/scripts/456.py b/scripts/456.py
new file mode 100644
index 0000000..21eb097
--- /dev/null
+++ b/scripts/456.py
@@ -0,0 +1,14 @@
+from pathlib import Path
+import hou
+import json
+
+# This file runs when a .hip file is loaded
+
+current_file = hou.hipFile.path()
+state_file = Path(hou.getenv("HOUDINI_USER_PREF_DIR")) / "st_data" / "state.json"
+data = {"last_opened_file": current_file}
+
+# Write to JSON
+updates = {"last_file": current_file}
+with open(state_file, 'w') as f:
+ json.dump(updates, f, indent=4)
diff --git a/scripts/OnCreated.py b/scripts/OnCreated.py
new file mode 100644
index 0000000..50fa6a0
--- /dev/null
+++ b/scripts/OnCreated.py
@@ -0,0 +1,13 @@
+import hou
+from hc import Prefs
+from hc import Node
+# import from hc.NetworkEditor import snapToGrid
+
+# Get the node that was just created
+node = Node(kwargs['node'])
+
+# Force the shape to your desired JSON name
+# (e.g., "rect", "circle", or your custom "my_shape")
+# node.setUserData("nodeshape", "squared")
+node.setColor(hou.Color(Prefs().node_color))
+# snapToGrid(node)