Zahlenwerte gerundet, Ausgabe in seperatre .json für Rack, Distributors und Sensoren. Rack json mit Bennung der Racks

This commit is contained in:
2025-05-08 09:41:36 +02:00
parent 27c2984b7a
commit ef1e78de2e
+15 -11
View File
@@ -33,7 +33,7 @@ def merge_two_dicts(x, y):
return z
def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
"""hole alle Positionen der Eingänge
"""hole alle Positionen der Eingänge !!Sensor Positionen erst nach Offsett-Addition "Mitte-Mitte"!!
"""
allIds = dict()
SpecialKeys = ["MB", # Separator
@@ -71,7 +71,7 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
pos_midx = pos.x + breite_marker*0.5
pos_midy = pos.y + hoehe_marker*0.5
ld["pos"] = (pos_midx, pos_midy)
ld["pos"] = (round(pos_midx, 1), round(pos_midy, 1))
# Nur wenn eine ID vorhanden ist, und eine gültige Position existiert
if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2:
@@ -83,7 +83,7 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
def get_subdistributor_positions(msp):
"""hole alle Positionen der Unterverteiler
"""hole alle Positionen der Unterverteiler !!UV-Positionen bereits "Mitte-Mitte"!!
"""
# # Über alle Texte laufen
# for text in msp.query('MTEXT'):
@@ -106,7 +106,7 @@ def get_subdistributor_positions(msp):
match = re.search(r"UC\w+", text.dxf.text)
if match:
nameUC = match.group(0)
ret[nameUC] = text.dxf.insert
ret[nameUC] = (round(text.dxf.insert[0],1), round(text.dxf.insert[1],1)) #nur x und y Koordinate in Json schreiben
return ret
@@ -125,17 +125,21 @@ def print_polyline(e):
print("Diese Polyline ist geschlossen.")
def get_rack_positions(msp):
"""hole alle Positionen aller Kabelpritschen
"""
"""hole alle Positionen aller Kabelpritschen und nummeriere Racks"""
ret = dict()
rack_counter = 1 #Zaehler für Rack Nummerierung
ret = list()
for e in msp.query('LWPOLYLINE[layer=="PRITSCHE_200-60"]'):
#print_polyline(e)
poly = list()
rack_key = f"Rack_{rack_counter}"
ret[rack_key] = dict()
node_counter = 1
for x, y, start_width, end_width, bulge in e.get_points(): # Gibt Tuple (x, y, start_width, end_width, bulge)
point = (x,y)
poly.append(point)
ret.append(poly)
node_key = f"Node_{node_counter}"
ret[rack_key][node_key] = [round(x,1), round(y,1)]
node_counter +=1
rack_counter +=1
# iterate over all entities in modelspace
# for e in msp:
# if e.dxftype() == "LINE":