#!/usr/bin/env bash # ────────────────────────────────────────────────────────── # hhb — Hermes-Houdini Bridge Client # Sends Python/hou commands to a running Houdini session # via SSH + hcommand. Results returned via temp file. # ────────────────────────────────────────────────────────── set -euo pipefail HOST="${HHB_HOST:-niklas@192.168.178.39}" PORT="${HHB_PORT:-12345}" HCOMMAND="${HHB_HCOMMAND:-/opt/hfs21.0/bin/hcommand}" usage() { cat <<'EOF' Usage: hhb [args] Commands: eval Execute Python code in the running Houdini session. script Send a Python script file to Houdini and execute it. get-selected Print paths and types of selected nodes. get-param Get value of a parameter on the first selected node. set-param Set a parameter on the first selected node. get-inputs Print input connections of the first selected node. status Check if the bridge port is open. help Show this help. EOF exit 0 } # ── Core: write Python script, execute, read back output ─ run_houdini_python() { # $1: Python code (as a string) # Writes code to /tmp/hhb_script.py, executes via hcommand, # reads output from /tmp/hhb_out.txt local python_code="$1" local sid="$$" # Upload the script printf '%s' "$python_code" | ssh "$HOST" "cat > /tmp/hhb_script_${sid}.py" # Execute via hcommand ssh "$HOST" "$HCOMMAND $PORT 'python /tmp/hhb_script_${sid}.py'" 2>/dev/null || true # Read output file ssh "$HOST" "cat /tmp/hhb_out_${sid}.txt 2>/dev/null" || echo "" # Cleanup ssh "$HOST" "rm -f /tmp/hhb_script_${sid}.py /tmp/hhb_out_${sid}.txt" 2>/dev/null || true } # Wrap user code to capture output via temp file wrap_python() { local code="$1" local sid="$$" cat <&1) || { echo "Bridge INACTIVE — Houdini not reachable or port $PORT closed." return 1 } echo "$output" | sed 's/^->\s*//' } cmd_eval() { [[ $# -ge 1 ]] || { echo "Usage: hhb eval "; exit 1; } local sid="$$" local code code=$(cat <"; exit 1; } local script_path="$1" local sid="$$" [[ -f "$script_path" ]] || { echo "File not found: $script_path"; exit 1; } # Read the script, wrap in output capture local code code=$(cat "$script_path") local wrapped wrapped=$(cat <"; exit 1; } local parm="$1" local sid="$$" local code code=$(cat < "; exit 1; } local parm="$1" local val="$2" local sid="$$" local code code=$(cat <