#! python 3 # -*- coding: utf-8 -*- """ werkzeuge.py WERKZEUGE-Panel: Architektur-orientierte Toolbar als React-WebView. Feuert Rhino-Befehle via RunScript bei Button-Klick. """ import os import sys import Rhino import scriptcontext as sc _HERE = os.path.dirname(os.path.abspath(__file__)) if _HERE not in sys.path: sys.path.insert(0, _HERE) import panel_base PANEL_GUID_STR = "6d9f5040-7e1f-4f2b-c4d5-f6071829304a" class WerkzeugeBridge(panel_base.BaseBridge): def __init__(self): panel_base.BaseBridge.__init__(self, "werkzeuge") def _on_ready(self): # Keine initialen Daten noetig — Toolbar ist statisch pass def handle(self, data): if not isinstance(data, dict): return t = data.get("type", "") p = data.get("payload") or {} if not isinstance(p, dict): p = {} if t == "READY": self._on_ready() elif t == "RUN": cmd = p.get("cmd") if cmd and isinstance(cmd, str): # Whitelist: alles muss mit "_" beginnen (Rhino-Befehl) und # darf keine Zeilenumbrueche oder Semikolons enthalten. cmd = cmd.strip() if cmd.startswith("_") and "\n" not in cmd and ";" not in cmd: try: Rhino.RhinoApp.RunScript(cmd, False) print("[WERKZEUGE] {}".format(cmd)) except Exception as ex: print("[WERKZEUGE] RunScript-Fehler:", ex) else: print("[WERKZEUGE] Befehl ignoriert (kein '_' Praefix oder unsicher):", cmd) def _bridge_factory(): return WerkzeugeBridge() panel_base.register_and_open("werkzeuge", "WERKZEUGE", PANEL_GUID_STR, _bridge_factory, icon_spec=("build", "#3a6fa8"))