Abfrage, welcher Typ das jeweilige Element ist. Wegwerfen von nicht gebrauchten.
This commit is contained in:
+34
-25
@@ -36,7 +36,7 @@ def merge_two_dicts(x, y):
|
|||||||
z.update(y)
|
z.update(y)
|
||||||
return z
|
return z
|
||||||
|
|
||||||
def get_attributes_of_insert(insert):
|
def get_type_of_name(name):
|
||||||
|
|
||||||
SpecialKeys = ["MB", # Separator
|
SpecialKeys = ["MB", # Separator
|
||||||
"MA", # Motor
|
"MA", # Motor
|
||||||
@@ -44,7 +44,7 @@ def get_attributes_of_insert(insert):
|
|||||||
"BP" # Schalter Druckluft
|
"BP" # Schalter Druckluft
|
||||||
]
|
]
|
||||||
|
|
||||||
KabelKey = "WD_"
|
KabelKey = ["WD"]
|
||||||
DropKeys = [
|
DropKeys = [
|
||||||
"FC", # Motorschutzschalter
|
"FC", # Motorschutzschalter
|
||||||
"PF", # Leuchtmelder
|
"PF", # Leuchtmelder
|
||||||
@@ -53,8 +53,29 @@ def get_attributes_of_insert(insert):
|
|||||||
"QA", # Hauptschütz
|
"QA", # Hauptschütz
|
||||||
"SF" # Drucktaster
|
"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 = ""
|
id = ""
|
||||||
ld = dict()
|
ld = dict()
|
||||||
|
typ = 'unknown'
|
||||||
for attrib in insert.attribs:
|
for attrib in insert.attribs:
|
||||||
attr_tag = attrib.dxf.tag
|
attr_tag = attrib.dxf.tag
|
||||||
attr_text = attrib.dxf.text
|
attr_text = attrib.dxf.text
|
||||||
@@ -62,34 +83,21 @@ def get_attributes_of_insert(insert):
|
|||||||
continue # Überspringe Blöcke ohne Attribute
|
continue # Überspringe Blöcke ohne Attribute
|
||||||
#print(f"Attribut Name: {attrib.dxf.tag}, Wert: {attrib.dxf.text}")
|
#print(f"Attribut Name: {attrib.dxf.tag}, Wert: {attrib.dxf.text}")
|
||||||
ld[attr_tag] = attr_text
|
ld[attr_tag] = attr_text
|
||||||
typ = 'unknown'
|
|
||||||
if attr_tag == "IO":
|
if attr_tag == "IO":
|
||||||
|
typ = get_type_of_name(attr_text)
|
||||||
id = attr_text
|
id = attr_text
|
||||||
#print(f"-- coord io {id}--: {attrib.dxf.insert}") # position des Blocks
|
#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
|
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))
|
ld["pos"] = (round(pos.x, 1), round(pos.y, 1))
|
||||||
typ = "Sensor"
|
|
||||||
|
|
||||||
if attr_tag == "B":
|
if attr_tag == "B":
|
||||||
# Suche nach Sensoren
|
# Suche nach Sensoren
|
||||||
for spec in SpecialKeys:
|
typ = get_type_of_name(attr_text)
|
||||||
if spec in attr_text:
|
id = 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
|
|
||||||
|
|
||||||
if attr_tag == "REALE_POSITION" and attr_text == "x":
|
if attr_tag == "REALE_POSITION" and attr_text == "x":
|
||||||
|
#typ = get_type_of_name(attr_text)
|
||||||
#print(f"-- coord real --: {attrib.dxf.insert}")
|
#print(f"-- coord real --: {attrib.dxf.insert}")
|
||||||
pos = attrib.dxf.insert #Position Ecke unten links von "x"-Marker auslesen
|
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
|
midx = pos[0] + breite_marker * 0.5
|
||||||
midy = pos[1] + hoehe_marker * 0.5
|
midy = pos[1] + hoehe_marker * 0.5
|
||||||
ld["pos"] = (round(midx, 1), round(midy, 1))
|
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:
|
def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple:
|
||||||
"""hole alle Positionen der Eingänge !!Sensor Positionen erst nach Offsett-Addition "Mitte-Mitte"!!
|
"""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()
|
allSensors = dict()
|
||||||
allCables = dict()
|
allCables = dict()
|
||||||
|
allunknowns = dict()
|
||||||
|
allSchaltschrank = dict()
|
||||||
|
|
||||||
for insert in iterdxf.modelspace(dxf_path):
|
for insert in iterdxf.modelspace(dxf_path):
|
||||||
if insert.dxftype() != 'INSERT':
|
if insert.dxftype() != 'INSERT':
|
||||||
@@ -153,9 +162,11 @@ def get_input_positions_iter(dxf_path) -> tuple:
|
|||||||
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:
|
||||||
|
allunknowns[id] = ld
|
||||||
# Falls das Objekt ein Teil des Schaltschranks o.ä ist, dann nichts merken
|
# Falls das Objekt ein Teil des Schaltschranks o.ä ist, dann nichts merken
|
||||||
pass
|
|
||||||
|
|
||||||
return allSensors, allCables
|
return allSensors, allCables
|
||||||
|
|
||||||
@@ -446,8 +457,6 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
use_iter = True
|
use_iter = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
res_sens = dict()
|
res_sens = dict()
|
||||||
res_cables = dict()
|
res_cables = dict()
|
||||||
res_dist = dict()
|
res_dist = dict()
|
||||||
|
|||||||
Reference in New Issue
Block a user