24f6b76f06
- EBENEN: drawing levels updated, sublayer not found, saved/verified - GESTALTUNG: Linetypes before/after, fill field, opened/focused - CLIP: disabled done - ELEMENTE: Bulk-op, Listener bail - Global: not found, not available, unchanged, failed, present
80 lines
2.5 KiB
Python
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("[BEGIN-CMD] 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("[BEGIN-CMD] Gestaltung-Panel opened/focused")
|
|
except Exception as ex:
|
|
print("[BEGIN-CMD] OpenPanel:", ex)
|
|
try:
|
|
Rhino.RhinoApp.RunScript(
|
|
'-_ShowPanel "DOSSIER Gestaltung"', False)
|
|
except Exception: pass
|
|
except Exception as ex:
|
|
print("[BEGIN-CMD] 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("[BEGIN-CMD] Hook installed (verbose={})".format(bool(verbose)))
|
|
except Exception as ex:
|
|
print("[BEGIN-CMD] install:", ex)
|
|
|
|
|
|
def set_verbose(flag):
|
|
sc.sticky[_VERBOSE_KEY] = bool(flag)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
install(verbose=True)
|