Files
DOSSIER/rhino/begin_cmd_hook.py
T
karim b9a2124026 Rename all log tags to match English module names
[EBENEN] → [LAYERS], [EBENEN-BE] → [LAYERS-BE]
[ZEICHNUNGSEBENEN] → [DRAWING-LEVELS]
[GESTALTUNG] → [STYLES]
[OBERLEISTE] → [TOOLBAR]
[WERKZEUGE] → [TOOLS]
[DIMENSIONEN] → [DIMENSIONS]
[AUSSCHNITTE] → [VIEWPORTS]
[MASSSTAB] → [SCALE]
[SCHNITT] → [SECTION], [SCHNITT_GRIPS] → [SECTION-GRIPS]
[WAND_GRIPS] → [WALL-GRIPS], [TREPPE_GRIPS] → [STAIR-GRIPS]
[CURVE_DOTS] → [CURVE-DOTS]
[panel_base] → [CORE]
[ALIAS-LOADER] → [ALIASES]
[BEGIN-CMD] → [CMD-HOOK]
2026-06-06 12:48:27 +02:00

80 lines
2.5 KiB
Python

#! python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (C) 2026 Karim Gabriele Varano
"""
begin_cmd_hook.py
Hook auf Rhino.Commands.Command.BeginCommand. Wenn der User ein Drawing-
Command startet (Line, Polyline, Rectangle, Circle etc.), oeffnen wir
automatisch das DOSSIER-Gestaltung-Panel und bringen es in den Vordergrund.
Idempotent — Re-Install nach _reset_panels deregistriert alten Handler.
"""
import Rhino
import scriptcontext as sc
import System
# Commands bei denen wir Gestaltung-Panel fokussieren.
# CommandEnglishName ohne Underscore-Prefix.
_DRAWING_COMMANDS = {
"Line", "Polyline", "Curve", "InterpCrv",
"Arc", "Circle", "Ellipse",
"Rectangle", "Polygon",
"Hatch", "Text",
"Point", "Points",
"InfiniteLine",
}
_GESTALTUNG_PANEL_GUID = "4b8d3f2e-5c9d-4e0f-b2c3-d4e5f6071829"
_HANDLER_KEY = "_dossier_begin_cmd_handler"
_VERBOSE_KEY = "_dossier_begin_cmd_verbose"
def _on_begin_command(sender, e):
try:
cmd = getattr(e, "CommandEnglishName", "") or ""
if sc.sticky.get(_VERBOSE_KEY):
print("[CMD-HOOK] cmd='{}'".format(cmd))
if cmd not in _DRAWING_COMMANDS: return
try:
guid = System.Guid(_GESTALTUNG_PANEL_GUID)
Rhino.UI.Panels.OpenPanel(guid)
try:
Rhino.UI.Panels.FocusPanel(guid)
except Exception: pass
if sc.sticky.get(_VERBOSE_KEY):
print("[CMD-HOOK] Gestaltung-Panel opened/focused")
except Exception as ex:
print("[CMD-HOOK] OpenPanel:", ex)
try:
Rhino.RhinoApp.RunScript(
'-_ShowPanel "DOSSIER Gestaltung"', False)
except Exception: pass
except Exception as ex:
print("[CMD-HOOK] handler:", ex)
def install(verbose=False):
"""Einmalige Registrierung. Bei Re-Install (z.B. nach _reset_panels)
wird der alte Handler-Ref aus sc.sticky deregistriert."""
old = sc.sticky.get(_HANDLER_KEY)
if old is not None:
try: Rhino.Commands.Command.BeginCommand -= old
except Exception: pass
try:
Rhino.Commands.Command.BeginCommand += _on_begin_command
sc.sticky[_HANDLER_KEY] = _on_begin_command
sc.sticky[_VERBOSE_KEY] = bool(verbose)
print("[CMD-HOOK] Hook installed (verbose={})".format(bool(verbose)))
except Exception as ex:
print("[CMD-HOOK] install:", ex)
def set_verbose(flag):
sc.sticky[_VERBOSE_KEY] = bool(flag)
if __name__ == "__main__":
install(verbose=True)