git clone https://git.lucas.co/hou-control.git
hc: implement Restart Houdini and add to menu/panel
MainMenuCommon.xml | 8 ++++----
python3.11libs/hc/hcmaps.py | 1 +
python3.11libs/hc/hcsession.py | 34 ++++++++++++++++++++++++++--------
3 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/MainMenuCommon.xml b/MainMenuCommon.xml
index ed6d01d..b4e81f3 100755
--- a/MainMenuCommon.xml
+++ b/MainMenuCommon.xml
@@ -76,10 +76,10 @@
<scriptCode><![CDATA[from hc import HCSession; HCSession().toggleAllTabs()]]></scriptCode>
</scriptItem>
- <!-- <scriptItem id="h.hc_session_restarthoudini"> -->
- <!-- <label>Restart Houdini</label> -->
- <!-- <scriptCode><![CDATA[from hc import HCSession; HCSession().restartHoudini()]]></scriptCode> -->
- <!-- </scriptItem> -->
+ <scriptItem id="h.hc_session_restarthoudini">
+ <label>Restart Houdini</label>
+ <scriptCode><![CDATA[from hc import HCSession; HCSession().restartHoudini()]]></scriptCode>
+ </scriptItem>
<scriptItem id="h.hc_session_togglemenus">
<label>Toggle Menus</label>
diff --git a/python3.11libs/hc/hcmaps.py b/python3.11libs/hc/hcmaps.py
index 65294c7..40c56ae 100644
--- a/python3.11libs/hc/hcmaps.py
+++ b/python3.11libs/hc/hcmaps.py
@@ -21,6 +21,7 @@ class HCMaps:
'Reload HC': session.reloadHC,
'Reload Hotkeys': session.reloadHotkeys,
'Reload Keycam': session.reloadKeycam,
+ 'Restart Houdini': session.restartHoudini,
# 'Rename Tabs': session.renameTabs,
'Save': session.save,
'Set Type: NetworkEditor': lambda: self.tab.setType('NetworkEditor'),
diff --git a/python3.11libs/hc/hcsession.py b/python3.11libs/hc/hcsession.py
index c61f890..acdb197 100644
--- a/python3.11libs/hc/hcsession.py
+++ b/python3.11libs/hc/hcsession.py
@@ -271,14 +271,32 @@ class HCSession:
for callback in callbacks:
hou.ui.removeEventLoopCallback(callback)
- # def restartHoudini(self):
- # import os
- # import subprocess
- # executable = sys.argv[0]
- # executable = os.environ.get("HFS") + "/bin/houdini"
- # subprocess.Popen([executable])
- # hou.exit()
- # return
+ def restartHoudini(self):
+ import os
+ import subprocess
+ import sys
+
+ # Save current state so 123.py knows what to open if we don't pass it explicitly,
+ # but we will pass it explicitly to be safe.
+ current_hip = hou.hipFile.path()
+ if not hou.hipFile.isUntitled():
+ hou.hipFile.save()
+
+ # Get the path to the houdini executable
+ # On Linux, this is usually in $HFS/bin/houdini
+ hfs = os.environ.get("HFS")
+ if hfs:
+ executable = os.path.join(hfs, "bin", "houdini")
+ else:
+ executable = "houdini" # Fallback to path
+
+ # Launch new process
+ # We pass the current hip file as an argument so it opens directly
+ args = [executable, current_hip]
+ subprocess.Popen(args, close_fds=True)
+
+ # Exit current instance
+ hou.exit()
def save(self):
hou.hipFile.save()