Zeile mit überprüfung ob pos in ld steht auskommentiert. Sonst wird kein merge der dicts ausgefürt und artikelnummer des sensors aus anderem INSERT findet den weg nicht in allSensors da kein pos eintrag dort vorhanden

This commit is contained in:
2025-06-10 09:51:00 +02:00
parent 6ffb9c72d5
commit 47ab065387
+16 -16
View File
@@ -48,7 +48,6 @@ def get_type_of_name(name):
DropKeys = [ DropKeys = [
"FC", # Motorschutzschalter "FC", # Motorschutzschalter
"PF", # Leuchtmelder "PF", # Leuchtmelder
"SF",
"DI", # Feedback vom Gerät "DI", # Feedback vom Gerät
"QA", # Hauptschütz "QA", # Hauptschütz
"SF" # Drucktaster "SF" # Drucktaster
@@ -115,6 +114,8 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple:
""" """
allSensors = dict() allSensors = dict()
allCables = dict() allCables = dict()
allunknowns = dict()
allSchaltschrank = dict()
# Über alle Blockreferenzen (INSERT) im Modelspace laufen # Über alle Blockreferenzen (INSERT) im Modelspace laufen
for insert in msp.query('INSERT'): for insert in msp.query('INSERT'):
@@ -124,23 +125,25 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple:
ld, id, typ = get_attributes_of_insert(insert) ld, id, typ = get_attributes_of_insert(insert)
# Nur wenn eine ID vorhanden ist, und eine gültige Position existiert # Verarbeite je nach Typ
if typ == "Sensor": if typ == "Sensor":
if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2:
if id in allSensors: if id in allSensors:
allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" allSensors[id] = merge_two_dicts(allSensors[id], ld)
else: else:
allSensors[id] = ld allSensors[id] = ld
elif typ == "Kabel": elif typ == "Kabel":
allCables[id] = ld allCables[id] = ld
elif typ == "Schaltschrankelement":
allSchaltschrank[id] = ld
else: else:
# Falls das Objekt ein Teil des Schaltschranks o.ä ist, dann nichts merken allunknowns[id] = ld
pass
return allSensors, allCables return allSensors, allCables
def get_input_positions_iter(dxf_path) -> tuple: def get_input_positions_iter(dxf_path) -> tuple:
""" """
Iterative Version für große DXF-Dateien mit iterdxf (kein Context Manager!). Iterative Version für große DXF-Dateien mit iterdxf
""" """
allSensors = dict() allSensors = dict()
allCables = dict() allCables = dict()
@@ -155,18 +158,17 @@ def get_input_positions_iter(dxf_path) -> tuple:
# Nur wenn eine ID vorhanden ist, und eine gültige Position existiert # Nur wenn eine ID vorhanden ist, und eine gültige Position existiert
if typ == "Sensor": if typ == "Sensor":
if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: #if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2:
if id in allSensors: if id in allSensors:
allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos"
else: else:
allSensors[id] = ld allSensors[id] = ld
elif typ == "Kabel": elif typ == "Kabel":
allCables[id] = ld allCables[id] = ld
elif typ == "Schaltschrankelement": elif typ == "Schaltschrankelement":
allSchaltschrank[id] = ld allSchaltschrank[id] = ld
else: else:
allunknowns[id] = ld allunknowns[id] = ld
# Falls das Objekt ein Teil des Schaltschranks o.ä ist, dann nichts merken
return allSensors, allCables return allSensors, allCables
@@ -448,13 +450,13 @@ if __name__ == '__main__':
filename = args.filename filename = args.filename
(dxf_path, dexists) = check_file_in_work(work_dir, filename) (dxf_path, dexists) = check_file_in_work(work_dir, filename)
zeitanfang = time.time()
if dxf_is_binary(dxf_path): # Wenn dxf eine binary ist, dann komplett parsen und modelspace anlegen if dxf_is_binary(dxf_path): # Wenn dxf eine binary ist, dann komplett parsen und modelspace anlegen
doc = get_dxf_file(dxf_path) doc = get_dxf_file(dxf_path)
print("Given .dxf-file is binary dxf. Proceeding to read file. Watch RAM-usage.")
msp = doc.modelspace() msp = doc.modelspace()
use_iter = False use_iter = False
else: else:
print("Given .dxf-file is ASCII-dxf. Proceeding to user iterative functions. Process may take longer.")
use_iter = True use_iter = True
res_sens = dict() res_sens = dict()
@@ -530,8 +532,6 @@ if __name__ == '__main__':
res_not_found = check_existance(res_mappings, res_dist, res_sens) res_not_found = check_existance(res_mappings, res_dist, res_sens)
output_results["not_found"] = res_not_found output_results["not_found"] = res_not_found
write_results(to_json(output_results), work_dir, f"{basename}.json") write_results(to_json(output_results), work_dir, f"{basename}.json")
zeitende = time.time()
print(zeitende-zeitanfang)
else: else:
parser.print_help() parser.print_help()