From 6ffb9c72d563f822734515bcdebb76a30872f204 Mon Sep 17 00:00:00 2001 From: lertlmaier Date: Fri, 6 Jun 2025 17:58:51 +0200 Subject: [PATCH] Abfrage, welcher Typ das jeweilige Element ist. Wegwerfen von nicht gebrauchten. --- lib/getpositions.py | 59 ++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/lib/getpositions.py b/lib/getpositions.py index 682d6f7..77774f6 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -36,7 +36,7 @@ def merge_two_dicts(x, y): z.update(y) return z -def get_attributes_of_insert(insert): +def get_type_of_name(name): SpecialKeys = ["MB", # Separator "MA", # Motor @@ -44,7 +44,7 @@ def get_attributes_of_insert(insert): "BP" # Schalter Druckluft ] - KabelKey = "WD_" + KabelKey = ["WD"] DropKeys = [ "FC", # Motorschutzschalter "PF", # Leuchtmelder @@ -53,8 +53,29 @@ def get_attributes_of_insert(insert): "QA", # Hauptschütz "SF" # Drucktaster ] + + prefix = name[0:2] + if prefix in SpecialKeys: + typ = "Sensor" + + # Suche nach Kabel + elif prefix in KabelKey: + typ = "Kabel" + + # suche nach Items die wir nicht weiter verfolgen + elif prefix in DropKeys: + typ = "Schaltschrankelement" + + else: + typ = "unknown" + + return typ + +def get_attributes_of_insert(insert): + id = "" ld = dict() + typ = 'unknown' for attrib in insert.attribs: attr_tag = attrib.dxf.tag attr_text = attrib.dxf.text @@ -62,34 +83,21 @@ def get_attributes_of_insert(insert): continue # Überspringe Blöcke ohne Attribute #print(f"Attribut Name: {attrib.dxf.tag}, Wert: {attrib.dxf.text}") ld[attr_tag] = attr_text - typ = 'unknown' + if attr_tag == "IO": + typ = get_type_of_name(attr_text) id = attr_text #print(f"-- coord io {id}--: {attrib.dxf.insert}") # position des Blocks pos = attrib.dxf.insert #Position aufzeichnen und bei Bedarf später mit REAL_POS überschreiben ld["pos"] = (round(pos.x, 1), round(pos.y, 1)) - typ = "Sensor" if attr_tag == "B": # Suche nach Sensoren - for spec in SpecialKeys: - if spec in attr_text: - id = attr_text - typ = "Sensor" - - # Suche nach Kabel - if KabelKey in attr_text: - id = attr_text - typ = "Kabel" - - # suche nach Items die wir nicht weiter verfolgen - for dropkey in DropKeys: - if dropkey in attr_text: - typ = "Schaltschrankelement" - id = attr_text - return {}, id, typ + typ = get_type_of_name(attr_text) + id = attr_text if attr_tag == "REALE_POSITION" and attr_text == "x": + #typ = get_type_of_name(attr_text) #print(f"-- coord real --: {attrib.dxf.insert}") pos = attrib.dxf.insert #Position Ecke unten links von "x"-Marker auslesen @@ -99,9 +107,8 @@ def get_attributes_of_insert(insert): midx = pos[0] + breite_marker * 0.5 midy = pos[1] + hoehe_marker * 0.5 ld["pos"] = (round(midx, 1), round(midy, 1)) - typ = "Sensor" - return ld, id, typ + return (ld, id, typ) def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple: """hole alle Positionen der Eingänge !!Sensor Positionen erst nach Offsett-Addition "Mitte-Mitte"!! @@ -137,6 +144,8 @@ def get_input_positions_iter(dxf_path) -> tuple: """ allSensors = dict() allCables = dict() + allunknowns = dict() + allSchaltschrank = dict() for insert in iterdxf.modelspace(dxf_path): if insert.dxftype() != 'INSERT': @@ -153,9 +162,11 @@ def get_input_positions_iter(dxf_path) -> tuple: allSensors[id] = ld elif typ == "Kabel": allCables[id] = ld + elif typ == "Schaltschrankelement": + allSchaltschrank[id] = ld else: + allunknowns[id] = ld # Falls das Objekt ein Teil des Schaltschranks o.ä ist, dann nichts merken - pass return allSensors, allCables @@ -446,8 +457,6 @@ if __name__ == '__main__': else: use_iter = True - - res_sens = dict() res_cables = dict() res_dist = dict()