Files
Ornament-Generator-RNG/ornament_showcase/ornaments/bl.py
T
2026-11-16 23:50:40 +03:00

15 lines
738 B
Python

# Tiny client for the Blender MCP add-on (localhost:9876): python bl.py <script.py> or python bl.py -c "code"
import json, socket, sys
code = sys.argv[2] if sys.argv[1] == '-c' else open(sys.argv[1], encoding='utf-8').read()
if len(sys.argv) > 2 and sys.argv[1] != '-c': code = sys.argv[2] + '\n' + code # e.g. "NUMS=[208]"
s = socket.create_connection(('localhost', 9876), timeout=600)
s.sendall(json.dumps({'type': 'execute', 'code': code, 'strict_json': False}).encode() + b'\0')
buf = b''
while not buf.endswith(b'\0'):
chunk = s.recv(65536)
if not chunk: break
buf += chunk
r = json.loads(buf.rstrip(b'\0').decode())
for k in ('status', 'stdout', 'stderr', 'message', 'result'):
if r.get(k): print(f'[{k}]', r[k])