Files
Pier_v1/Code/tools/rhino_call.py
T

38 lines
1.2 KiB
Python

r"""Rhino 소켓 서버(포트 9876)에 직접 명령을 보낸다. MCP 도구가 세션에 없을 때 쓴다.
사용: python rhino_call.py get_scene_info
python rhino_call.py execute_code "<IronPython 코드>"
python rhino_call.py execute_code @파일경로.py
"""
import json
import socket
import sys
def call(cmd_type, params=None, host="127.0.0.1", port=9876, timeout=300):
with socket.create_connection((host, port), timeout=timeout) as s:
s.sendall(json.dumps({"type": cmd_type, "params": params or {}}).encode("utf-8"))
buf = b""
while True:
chunk = s.recv(1 << 20)
if not chunk:
break
buf += chunk
try:
return json.loads(buf.decode("utf-8"))
except ValueError:
continue
return json.loads(buf.decode("utf-8"))
if __name__ == "__main__":
sys.stdout.reconfigure(encoding="utf-8")
t = sys.argv[1]
p = {}
if t == "execute_code":
code = sys.argv[2]
if code.startswith("@"):
code = open(code[1:], encoding="utf-8").read()
p = {"code": code}
print(json.dumps(call(t, p), ensure_ascii=False, indent=1)[:6000])