attradd.py und add_attr.bat in set_attributs.py/.bat umbenannt
lib/attradd.py -> lib/set_attributs.py: Name besser passend zum Skript-Zweck (setzt Attribute, analog set_einfuegepkt / set_koords). bin/add_attr.bat -> bin/set_attributs.bat entsprechend angepasst. cfg/attradd.cfg: Kommentar auf neuen Skriptnamen aktualisiert. HOEHE/DREHUNG-Eintraege aus [bogen] und [weiche] entfernt, da diese Attribute jetzt dynamisch via ssg-cfg-or aus component_defaults.json bezogen werden (nicht mehr als statische ATTDEF-Defaults noetig). Ebenso RADIUS aus [weiche] entfernt (war redundant zu KurvenWinkel). doc/tools.md und CLAUDE.md: Alle Verweise auf attradd.py auf set_attributs.py aktualisiert. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
attradd.py - Fuegt Attribute (ATTDEF) zu allen Omniflo DXF-Dateien hinzu.
|
||||
set_attributs.py - Fuegt Attribute (ATTDEF) zu allen Omniflo DXF-Dateien hinzu.
|
||||
|
||||
Liest die Attribut-Konfiguration aus cfg/attradd.cfg und die Element-Daten
|
||||
aus data/json/omniflo_boegen.json und omniflo_weichen.json.
|
||||
@@ -13,7 +13,7 @@ Umgebungsvariablen:
|
||||
DXFM_RESULTS - Pfad zum results/-Verzeichnis
|
||||
|
||||
Aufruf:
|
||||
python lib/attradd.py [--number SIVASNR] [--dry-run]
|
||||
python lib/set_attributs.py [--number SIVASNR] [--dry-run]
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -157,11 +157,32 @@ ATTDEF_HEIGHT = 5.0
|
||||
ATTDEF_LAYER = "ATTRIB"
|
||||
|
||||
|
||||
def wrap_entities_in_block(doc, block_name):
|
||||
"""
|
||||
Verschiebt alle Entities aus dem Modelspace in eine Blockdefinition
|
||||
mit dem Namen block_name und fuegt eine Blockreferenz bei (0, 0) ein.
|
||||
Vorhandene Blockdefinition mit gleichem Namen wird ersetzt (fuer Re-Runs).
|
||||
"""
|
||||
msp = doc.modelspace()
|
||||
|
||||
# Vorhandene Blockdefinition entfernen
|
||||
if block_name in doc.blocks:
|
||||
doc.blocks.delete_block(block_name, safe=False)
|
||||
|
||||
blk = doc.blocks.new(block_name)
|
||||
|
||||
for entity in list(msp):
|
||||
msp.move_to_layout(entity, blk)
|
||||
|
||||
msp.add_blockref(block_name, (0, 0))
|
||||
|
||||
|
||||
def add_attdefs_to_dxf(dxf_path, output_path, attr_defs, json_entry, sivasnr,
|
||||
layer_value=""):
|
||||
"""
|
||||
Oeffnet eine DXF-Datei, fuegt ATTDEF-Entities in den Modelspace ein
|
||||
und speichert das Ergebnis.
|
||||
Oeffnet eine DXF-Datei, fuegt ATTDEF-Entities in den Modelspace ein,
|
||||
fasst alle Entities anschliessend in einen Block mit dem Namen sivasnr
|
||||
zusammen und speichert das Ergebnis.
|
||||
|
||||
attr_defs: Liste von (TAG, source_expression) aus der Config
|
||||
json_entry: Dict mit den JSON-Daten fuer dieses Element
|
||||
@@ -205,6 +226,9 @@ def add_attdefs_to_dxf(dxf_path, output_path, attr_defs, json_entry, sivasnr,
|
||||
y_pos += ATTDEF_SPACING
|
||||
count += 1
|
||||
|
||||
# Alle Entities (Geometrie + ATTDEFs) in Block mit Sivasnr-Namen fassen
|
||||
wrap_entities_in_block(doc, sivasnr)
|
||||
|
||||
doc.saveas(output_path)
|
||||
return count
|
||||
|
||||
@@ -219,7 +243,7 @@ def process_all(data_dir, cfg_path, results_dir, single_nr=None, dry_run=False):
|
||||
# Config laden
|
||||
attr_config = load_config(cfg_path)
|
||||
layer_map = attr_config.pop("layer", {})
|
||||
print(f"[attradd] Config geladen: {list(attr_config.keys())}")
|
||||
print(f"[set_attributs] Config geladen: {list(attr_config.keys())}")
|
||||
if layer_map:
|
||||
print(f" [layer] {len(layer_map)} Zuordnungen: "
|
||||
f"{', '.join(f'{k}={v}' for k, v in layer_map.items())}")
|
||||
@@ -231,7 +255,7 @@ def process_all(data_dir, cfg_path, results_dir, single_nr=None, dry_run=False):
|
||||
boegen = load_json(os.path.join(data_dir, "json", "omniflo_boegen.json"))
|
||||
weichen = load_json(os.path.join(data_dir, "json", "omniflo_weichen.json"))
|
||||
lookup = build_lookup(boegen, weichen)
|
||||
print(f"[attradd] {len(boegen)} Boegen, {len(weichen)} Weichen geladen.")
|
||||
print(f"[set_attributs] {len(boegen)} Boegen, {len(weichen)} Weichen geladen.")
|
||||
|
||||
# Ausgabeverzeichnis
|
||||
out_dir = os.path.join(results_dir, "omniflo")
|
||||
@@ -284,10 +308,10 @@ def process_all(data_dir, cfg_path, results_dir, single_nr=None, dry_run=False):
|
||||
errors += 1
|
||||
print(f" FEHLER: {sivasnr}: {e}")
|
||||
|
||||
print(f"\n[attradd] Fertig: {processed} verarbeitet, "
|
||||
print(f"\n[set_attributs] Fertig: {processed} verarbeitet, "
|
||||
f"{skipped} uebersprungen, {errors} Fehler.")
|
||||
if not dry_run:
|
||||
print(f"[attradd] Ausgabe in: {out_dir}")
|
||||
print(f"[set_attributs] Ausgabe in: {out_dir}")
|
||||
|
||||
|
||||
def main():
|
||||
@@ -317,7 +341,7 @@ def main():
|
||||
|
||||
cfg_path = os.path.join(cfg_dir, "attradd.cfg")
|
||||
if not os.path.exists(cfg_path):
|
||||
print(f"[attradd] FEHLER: Config nicht gefunden: {cfg_path}")
|
||||
print(f"[set_attributs] FEHLER: Config nicht gefunden: {cfg_path}")
|
||||
sys.exit(1)
|
||||
|
||||
process_all(data_dir, cfg_path, results_dir,
|
||||
Reference in New Issue
Block a user