diff --git a/lib/dxf2lib.py b/lib/dxf2lib.py index f70717b..54bdcc9 100644 --- a/lib/dxf2lib.py +++ b/lib/dxf2lib.py @@ -651,13 +651,12 @@ def calculate_insert_bounding_box(insert_entity, doc,src_doc,filename,parent_tra """ Berechnet die Bounding Box eines INSERTs inklusive Block-Inhalt """ - + try: # Block-Definition finden block_name = insert_entity.dxf.name src_blk = src_doc.blocks[block_name] - if block_name == "ccLab_2025312125317867_51": - print(filename) + if block_name in doc.blocks: dst_blk = doc.blocks[block_name] diff --git a/lib/plant2dxf.py b/lib/plant2dxf.py index d6a94a5..6c73022 100644 --- a/lib/plant2dxf.py +++ b/lib/plant2dxf.py @@ -89,7 +89,6 @@ def import_block(block_name: str, from_doc, to_doc) -> None: if block_name not in from_doc.blocks: raise ValueError(f"Block '{block_name}' nicht in Bibliothek gefunden.") src = from_doc.blocks[block_name] - # Sicherstellen, dass alle verwendeten Layer existieren try: used_layer_names = {e.dxf.layer for e in src if hasattr(e.dxf, "layer")} @@ -188,7 +187,8 @@ def handle_ils_2_0_kreisel(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, if i < len(positions): pos = (positions[i][0] + offset[0], positions[i][1] + offset[1]) import_block(blockname, lib_doc, doc) - bref = msp.add_blockref(blockname, pos, dxfattribs={"rotation": merkmale.get("Drehung")}) + blockref_layer = get_layer(doc, lib_doc, blockname) + bref = msp.add_blockref(blockname, pos, dxfattribs={"rotation": merkmale.get("Drehung"), "layer" : blockref_layer}) bref.add_auto_attribs({ATTR_TAG: teileid}) if verbose: print(f"[INFO] Block '{blockname}' (Kreisel) → {teileid} " @@ -249,8 +249,8 @@ def draw_kreisel_drehrichtung_markierung(msp, pos1, pos2, merkmale, lib_doc, doc if drehrichtung == "GUZS": rotation += 180 import_block("S-LP", lib_doc, doc) - - bref = msp.add_blockref("S-LP", (px, py), dxfattribs={"rotation": rotation}) + blockref_layer = get_layer(doc, lib_doc, "S-LP") + bref = msp.add_blockref("S-LP", (px, py), dxfattribs={"rotation": rotation,"layer": blockref_layer}) if verbose: print(f"[INFO] Drehrichtung '{drehrichtung}': S-LP oben bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}") # S-LP auf unterer Linie (Drehrichtung invertiert) @@ -262,14 +262,16 @@ def draw_kreisel_drehrichtung_markierung(msp, pos1, pos2, merkmale, lib_doc, doc if drehrichtung == "UZS": rotation += 180 import_block("S-LP", lib_doc, doc) - bref = msp.add_blockref("S-LP", (px, py), dxfattribs={"rotation": rotation}) + blockref_layer = get_layer(doc, lib_doc, "S-LP") + bref = msp.add_blockref("S-LP", (px, py), dxfattribs={"rotation": rotation , "layer": blockref_layer}) if verbose: print(f"[INFO] Drehrichtung '{drehrichtung}': S-LP unten bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}") def handle_standard(msp, blocknames, teileid, x, y, lib_doc, doc, verbose): for blockname in blocknames: import_block(blockname, lib_doc, doc) - bref = msp.add_blockref(blockname, (x, y)) + blockref_layer = get_layer(doc, lib_doc, blockname) + bref = msp.add_blockref(blockname, (x, y), dxfattribs={"layer": blockref_layer}) bref.add_auto_attribs({ATTR_TAG: teileid}) if verbose: print(f"[INFO] Block '{blockname}' (Standard) → {teileid} " @@ -311,8 +313,9 @@ def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, v pos = (start[0] + offset[0], start[1] + offset[1] ) if i == 0 else (ende[0] + offset[0], ende[1] + offset[1]) import_block(blockname, lib_doc, doc) + blockref_layer = get_layer(doc, lib_doc, blockname) bref = msp.add_blockref(blockname, pos, dxfattribs={ - "rotation": rotation}) + "rotation": rotation,"layer": blockref_layer}) bref.add_auto_attribs({ATTR_TAG: teileid}) if verbose: print( @@ -361,6 +364,24 @@ def handle_omniflo(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols) print(f"[WARN] Omniflo-Block '{blockname}' nicht in Bibliothek {lib_doc.filename}. Überspringe {teileid}.") return import_block(blockname, lib_doc, doc) + blockref_layer = get_layer(doc, lib_doc, blockname) + drehung = merkmale.get("Drehung") + + bref = msp.add_blockref(blockname, (x, y), dxfattribs={"xscale": 1.0, "yscale":1.0,"rotation": drehung, "layer": blockref_layer}) + + bref.add_attrib( + tag= "NAME", + text= merkmale.get("bezeichner"), + insert = (x,y), + + + + ) + bref.add_auto_attribs({ATTR_TAG: teileid}) + if verbose: + print(f"[INFO] Block '{blockname}' (Omniflo) → {teileid} ({x:.1f}, {y:.1f})") + +def get_layer(doc, lib_doc, blockname): src = lib_doc.blocks[blockname] try: used_layer_names = {e.dxf.layer for e in src if hasattr(e.dxf, "layer")} @@ -388,27 +409,7 @@ def handle_omniflo(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols) layer_counts[ln] = layer_counts.get(ln, 0) + 1 if layer_counts: blockref_layer = max(layer_counts.items(), key=lambda kv: kv[1])[0] - lib_block = lib_doc.blocks.get(blockname) - imported_block = doc.blocks.get(blockname) - if hasattr(lib_block.block.dxf, "base_point"): - imported_block.block.dxf.base_point = lib_block.block.dxf.base_point - if hasattr(lib_block.block.dxf, "layer"): - imported_block.block.dxf.layer= lib_block.block.dxf.layer - drehung = merkmale.get("Drehung") - - bref = msp.add_blockref(blockname, (x, y), dxfattribs={"xscale": 1.0, "yscale":1.0,"rotation": drehung, "layer": blockref_layer}) - - bref.add_attrib( - tag= "NAME", - text= merkmale.get("bezeichner"), - insert = (x,y), - - - - ) - bref.add_auto_attribs({ATTR_TAG: teileid}) - if verbose: - print(f"[INFO] Block '{blockname}' (Omniflo) → {teileid} ({x:.1f}, {y:.1f})") + return blockref_layer def normalize_func_name(name): return (