dd2a1734eb
- Shelf tool to open/close command port in Houdini - hhb client script (eval, script, get-selected, set-param, etc.) - Hermes skill with standard hou module workflows - Example: create pyro setup - hou module quick reference
88 lines
2.6 KiB
Python
88 lines
2.6 KiB
Python
"""
|
|
Hermes Bridge — Open a command port for remote control by Hermes Agent.
|
|
|
|
Usage (in Houdini Python Shell or Shelf Tool):
|
|
exec(open('/path/to/hermes_bridge.py').read())
|
|
|
|
Or install as shelf tool via the .shelf XML file.
|
|
"""
|
|
|
|
import hou
|
|
|
|
PORT = 12345
|
|
IP_MASK = "0.0.0.0" # Accept connections from anywhere. Use "+.+.+.+" for localhost only.
|
|
|
|
|
|
def get_bridge_status():
|
|
"""Check if the bridge port is open."""
|
|
result = hou.hscript("openport")[0]
|
|
if f"Port {PORT} is open" in result:
|
|
return True, result.strip()
|
|
return False, result.strip()
|
|
|
|
|
|
def open_bridge():
|
|
"""Open the command port."""
|
|
# Close first in case it's stuck
|
|
hou.hscript(f"closeport {PORT}")
|
|
result, _ = hou.hscript(f"openport {PORT} {IP_MASK}")
|
|
return result.strip()
|
|
|
|
|
|
def close_bridge():
|
|
"""Close the command port."""
|
|
result, _ = hou.hscript(f"closeport {PORT}")
|
|
return result.strip()
|
|
|
|
|
|
def show_dialog(message):
|
|
"""Show a non-blocking status dialog."""
|
|
hou.ui.displayMessage(
|
|
message,
|
|
title="Hermes Bridge",
|
|
severity=hou.severityType.ImportantMessage,
|
|
)
|
|
|
|
|
|
def main():
|
|
is_open, status = get_bridge_status()
|
|
|
|
if is_open:
|
|
# Bridge is already open — show status and offer close
|
|
choice = hou.ui.displayMessage(
|
|
f"Hermes Bridge is ACTIVE\n\nPort: {PORT}\nMask: {IP_MASK}\n\nClick 'Close' to shut down, or 'OK' to keep running.",
|
|
buttons=('OK', 'Close'),
|
|
default_choice=0,
|
|
close_choice=0,
|
|
title="Hermes Bridge",
|
|
severity=hou.severityType.Message,
|
|
)
|
|
if choice == 1:
|
|
result = close_bridge()
|
|
hou.ui.displayMessage(
|
|
f"Hermes Bridge CLOSED\n\n{result}",
|
|
title="Hermes Bridge",
|
|
severity=hou.severityType.ImportantMessage,
|
|
)
|
|
else:
|
|
# Bridge closed — offer to open
|
|
choice = hou.ui.displayMessage(
|
|
f"Hermes Bridge is INACTIVE\n\nPort {PORT} is not open.\n\nOpen it to allow Hermes remote control.",
|
|
buttons=('Open Bridge', 'Cancel'),
|
|
default_choice=0,
|
|
close_choice=1,
|
|
title="Hermes Bridge",
|
|
severity=hou.severityType.Warning,
|
|
)
|
|
if choice == 0:
|
|
result = open_bridge()
|
|
hou.ui.displayMessage(
|
|
f"Hermes Bridge ACTIVE\n\n{result}\n\nHermes can now control Houdini via:\n hhb eval \"hou.selectedNodes()[0].path()\"",
|
|
title="Hermes Bridge",
|
|
severity=hou.severityType.ImportantMessage,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|