Files
DOSSIER/csharp/DOSSIER/PythonRunner.cs
T
karim 18d6d98e07 DOSSIER Multi-Phase: C#-Plugin + Yak + Wandstile + UX-Polish
- C#-Plugin "DOSSIER" mit 23 nativen Commands (dWall, dDoor, ..., dSection)
  - Native Command-Namen + Autocomplete + saubere History
  - Idle-Defer + RhinoCode-API → kein _-RunPythonScript-Echo
  - Yak-Paket via build.sh, Install in ~/Library/.../packages/8.0/
- Launcher (Tauri):
  - dossier_init Tauri-Command + Setup-Tab in Settings
  - Yak-Install + StartupCommands-XML + Window-Layout in einem Schritt
  - clean-rhino.sh fuer reproduzierbare Resets
  - check_dossier_initialized triggert Auto-Open-Setup beim ersten Start
- Wand-Architektur:
  - Chain-Logik DEAKTIVIERT → jede Wand baut eigenes Volume (individuell
    anwaehlbar, einzeln loeschbar)
  - Polyline-Wand: jedes Segment = eigene Wand
  - Smart-Split fuer wand_axis/decke/dach/raum/aussparung/traeger
  - Auto-Group axis+volume → kein ChooseOne-Dialog, Delete loescht beides
  - Stale-Mitre-Fix: Joint-Cache wird vor jedem Wand-Regen invalidiert
  - T-Junction-Tolerance auf 1mm (war 1cm, lieferte falsche T-Mitres)
- Wand-Stile:
  - Schema in dossier_project_settings.wand_styles (Material + Prio +
    Default-Dicke + Referenz, oder Layered mit Schichten)
  - dWall-Command Stil-Picker
  - ProjectSettingsDialog: Sidebar-Layout (Pill-Selection) +
    Wandstile-Tab mit Liste/Editor
  - _wand_chain_compat benutzt style_id
  - Prio-Dominanz: hoehere Prio gewinnt Eckverbindung, niedrigere wird
    T-mitered (siehe _resolve_corner_miter)
- Cmd+G fuer Group (Geschoss-Up auf Alias 'gu')
- Welcome + Cheatsheet borderless mit X/Back-Buttons
- BeginCommand-Hook fuer Gestaltung-Panel-Auto-Open
- panel_base: Python.NET-Enum-Fix fuer Material-Render
2026-05-30 12:46:53 +02:00

80 lines
2.8 KiB
C#

// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2026 Karim Gabriele Varano
using System;
using System.IO;
using Rhino;
namespace DOSSIER;
/// <summary>
/// Geteilter Python-Script-Runner fuer Plugin-Startup (startup.py) und
/// Commands (cmd/*.py). Primaer ueber Rhino.Runtime.Code-API (CPython3),
/// Fallback ueber _-RunPythonScript-Command.
/// </summary>
internal static class PythonRunner
{
/// <summary>Fuehrt das Script aus. Versucht RhinoCode-API zuerst,
/// faellt auf _-RunPythonScript zurueck. Labels nur fuer Logs.</summary>
public static bool Run(string scriptPath, string label)
{
if (!File.Exists(scriptPath))
{
RhinoApp.WriteLine($"[DOSSIER] {label}: Script nicht gefunden: {scriptPath}");
return false;
}
if (TryRunViaRhinoCode(scriptPath, label)) return true;
try
{
RhinoApp.RunScript($"_-RunPythonScript \"{scriptPath}\"", echo: false);
return true;
}
catch (Exception ex)
{
RhinoApp.WriteLine($"[DOSSIER] {label} RunScript: {ex.Message}");
return false;
}
}
/// <summary>Wie Run, aber defern auf das naechste Idle-Event.
/// Erlaubt safe Invocation aus Plugin-OnLoad oder Command-RunCommand
/// (Rhino mag kein direktes _-RunPythonScript aus diesen Kontexten).</summary>
public static void RunDeferred(string scriptPath, string label)
{
EventHandler? handler = null;
handler = (sender, e) =>
{
RhinoApp.Idle -= handler;
Run(scriptPath, label);
};
RhinoApp.Idle += handler;
}
private static bool TryRunViaRhinoCode(string scriptPath, string label)
{
try
{
var spec = new Rhino.Runtime.Code.Languages.LanguageSpec("*.*.python", "3.*");
var lang = Rhino.Runtime.Code.RhinoCode.Languages.QueryLatest(spec);
if (lang == null) return false;
// RhinoCode.CreateCode(text) setzt __file__/sys.path NICHT automatisch
// — die DOSSIER-Scripts erwarten beides. Injizieren vorne rein.
var pathLit = scriptPath.Replace("\\", "/");
var preamble =
"import sys, os\n" +
$"__file__ = r'{pathLit}'\n" +
"sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))\n" +
"sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))\n";
var code = lang.CreateCode(preamble + File.ReadAllText(scriptPath));
var ctx = new Rhino.Runtime.Code.Execution.RunContext();
code.Run(ctx);
return true;
}
catch (Exception ex)
{
RhinoApp.WriteLine($"[DOSSIER] {label} RhinoCode: {ex.Message}");
return false;
}
}
}