utils enthält jetzt generelle Routinen der verschiedenen Programme. create_example refactored. utils wird jetzt entsprechend überall importiert

This commit is contained in:
2026-01-30 15:39:35 +01:00
parent 09ffb5d7b2
commit 222a2efbf6
6 changed files with 832 additions and 204 deletions
+1 -30
View File
@@ -20,6 +20,7 @@ from utils import (
merge_two_dicts,
to_json,
write_results,
extract_attributes_with_positions as attribs_to_dicts,
)
@@ -371,36 +372,6 @@ def create_new_id(id_: str, dict1: dict, dict2: dict, error_collector: ErrorColl
return f"{id_}@UNKNOWN" # Fallback für fehlenden SPS-Präfix
return f"{id_}@{sps_praefix}"
def attribs_to_dicts(insert_iterable) -> tuple[list, list]:
"""
Wandelt eine Iterable von INSERT-Objekten in zwei Listen um:
- all_inserts: Liste von Dictionaries mit Attribut-Tags und deren Textwerten
- all_positions: Liste von Dictionaries mit Attribut-Tags und deren (x, y, z)-Positionen (jeweils gerundet auf eine Nachkommastelle)
Jeder Eintrag in den Listen entspricht einem INSERT-Block mit Attributen.
Blöcke ohne Attribute werden übersprungen.
"""
all_inserts = list()
all_positions = list()
for insert in insert_iterable:
if insert.dxftype() != 'INSERT':
continue
itemdata = dict()
positions = dict()
typ = 'unknown'
for attrib in insert.attribs:
if len(insert.attribs) == 0:
continue # Überspringe Blöcke ohne Attribute
attr_tag = attrib.dxf.tag
attr_text = attrib.dxf.text
pos = attrib.dxf.insert
itemdata[attr_tag] = attr_text
positions[attr_tag] = (round(pos.x, 1), round(pos.y, 1), round(pos.z, 1))
if len(itemdata) > 0:
all_inserts.append(itemdata)
all_positions.append(positions)
return all_inserts, all_positions
def create_mappings(positions: dict) -> tuple[dict, dict]:
unterverteiler_pfad = ""
dnamen = dict()