Schalter für Einlesen von positions_json in drawdxf etfernt (bat-Datei und Python Skript angepasst)., Sensor dataclass in drawdxf entfernt

get_type_of_name_cfg als Config-basierte Methode statt hardcode geschrieben.
map_sensor_to_cable_cfg als config basierte methode mitsamt kürzung de Kabel, etc..
Erstellung von Betriebsmittelkennzeichner Config.
This commit is contained in:
2025-06-12 10:54:02 +02:00
parent cc36734790
commit 2657117c24
5 changed files with 99 additions and 14 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ call getpositions.bat --filename %1 -s -r -w %FILENAME%_positions.json
echo --erzeuge Graph mit Routing
call routing.bat --filename %FILENAME%_positions.json -w %FILENAME%_todraw.json
echo --zeichne Kabel in dxf Datei
call draw_dxf.bat --filename %FILENAME%_todraw.json --new %FILENAME%_cables.dxf -x %FILENAME%_cables.xlsx -p %FILENAME%_positions.json
call draw_dxf.bat --filename %FILENAME%_todraw.json --new %FILENAME%_cables.dxf -x %FILENAME%_cables.xlsx
move %PROJECT_WORK%\%FILENAME%_* %INSTALL_DIR%
pause
+38
View File
@@ -0,0 +1,38 @@
# Konfigurationsdatei, welche das Einlesen / Ignorieren bestimmter Blöcke anhand der Betriebsmittelkennzeichnung (BMK) steuert
# Configuration file that controls the reading / ignoring of certain blocks based on the equipment identification (BMK)
# Prefixes, that should be included in Routing-Process
[Routing-Include]
MA # Motor
MB # Ventil
QM # Ventil
BG # Stauesensor
BP # Duckluftschalter
BX # Scanner
# Prefixes, that should be ignored in Routing-Process
[Routing-Ignore]
FC # Motorschutzschalter
PF # Leuchtmelder
DI # Feedback von Gerät
QA # Hauptschütz
SF # Drucktaster an Schaltschrank
# Mapping of Equipment-Prefixes to Cable Types found in kabel.cfg
[Cable-Mapping]
# Format: PREFIX = Cabel-Sekcion[, Section2, ...]
MA = MA
MB = WD_Q
QM = WD_Q
BG = WD_I
BG-829422026 = WD_I-829422026 # Spezialfall für Sensor mit ArtiNr: 829422026
BG-720002003 = WD_I-720002003 # Spezialfall für Sensor mit ArtiNr: 720002003
BX = WF_B, WD_I # Scanner mit zwei benötigten Kabeln
# Adjustment of Cable-Lenght's due to for example existing connection cables on sensor
[Length-Adjustments]
# Format: PREFIX = Length (m) to subtract
BX = 4
+1 -1
View File
@@ -82,7 +82,7 @@
95.0=726001061
# Bezeichner jeder Verbindungsleitung
# Bezeichner jeder Verbindungsleitung (gekürzt)
[Sivasnummern]
725000015=4G1,5mm², Steuerleitung
722001300=M12 St-0°/ M8 Bu-0° 1m
+42 -10
View File
@@ -49,11 +49,6 @@ class Polylines:
errors_existing_dists: List[str]
errors_existing_sensors: List[str]
@dataclass
class Sensors:
name: str
artinr: str
pos: List[float]
def add_polyline(msp, points:Polyline, dxf_attribs):
pts = points.to_tuple()
@@ -125,7 +120,6 @@ def find_close_key(pos2sensors, x, y, tolerance=10): # !!! Toleranz nicht
return (px, py)
return None
def draw_sensors(plines, doc):
msp = doc.modelspace()
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M")
@@ -485,13 +479,47 @@ def map_sensor_to_cable(plines):
return sens2cable
def map_sensor_to_cable_cfg(plines):
sens2cable = defaultdict(list)
mapping = config_BMK["Cable-Mapping"]
for pl in plines.kabel:
sensor_name = pl.id.split('-')[-1]
cable_length = pl.length/1000
sensor_artinr = pl.s_artinr
name_prefix = sensor_name[:2]
# Suche nach Key in der BMK-Config
key_with_artnr = f"{name_prefix}-{sensor_artinr}"
if key_with_artnr in mapping:
section_list = mapping[key_with_artnr]
elif name_prefix in mapping:
section_list = mapping[name_prefix]
else:
sens2cable[pl.id].append("Kein Kabeltyp zugewiesen")
# Liste aus evtl. mehreren Sektionen erzeugen
sections = [s.strip for s in section_list.split(",")]
# Evtl. Kabelkürzung durchführen, fall Kabelschwanz vorhanden
if config_BMK.has_section("Length-Adjustments") and config_BMK.has_option("Length-Adjustments", name_prefix):
length_reduction = float(config_BMK.get("Length-Adjustments", name_prefix))
cable_length = max(0.0, cable_length-length_reduction)
# Kabel-Atikelnummer innerhalb der Sektion der kabel.cfg bestimmen
for section in sections:
cable_artnr = get_cable_artnr(section, cable_length)
if cable_artnr is None:
sens2cable[pl.id].append(f"Kabel länger als max. Kabellänge")
else:
sens2cable[pl.id].append(cable_artnr)
return sens2cable
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='draws a dxf file with the given cable coordinates', prog='drawdxf')
parser.add_argument('-f', '--filename', action='store', required=True, help='this json file contains all cables and its coordinates which should be drawn. Saved with an unique timestamp', metavar='myfile.json')
parser.add_argument('-p','--positions', action='store', required=True, help='this json file contains positional information written by getpositions', metavar='myfile.json')
parser.add_argument('-d', '--dxf', action='store', help='this dxf drawing will be copied and the new layer with the cables will be added. Original file must be added with --origin', metavar='myfile.dxf')
parser.add_argument('-c', '--copy_layer', action='store', help='copy layers of racks, sensors, distributors into a new .dxf-file. File also contains cable paths. Original file must be added with --origin', metavar='original.dxf')
parser.add_argument('-n', '--new', action='store', help='create a new dxf file only with cables in it. Name is basename and a timestamp')
@@ -519,20 +547,24 @@ if __name__ == '__main__':
exit()
plines = model_from_json(json_path)
sensors = parse_sensors_from_json(positions_path)
# Allgemeine Config laden
config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config.optionxform = lambda option: option # preserve case for letters
config.read(os.path.join(config_dir, "allgemein.cfg"))
# Config für Kabel-Atikelnummern laden
# Config für Kabel-Artikelnummern laden
cable_cfg = configparser.ConfigParser()
cable_cfg.optionxform = str #Keys case-sensitive
with open(os.path.join(config_dir, "kabel.cfg"), encoding="utf-8") as f:
cable_cfg.read_file(f)
# Betriebsmittelkennzeichnungs-Config laden
config_BMK = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config_BMK.optionxform = lambda option: option # preserve case for letters
config_BMK.read(os.path.join(config_dir, "BMK.cfg"))
dxf_file = args.dxf
if args.dxf or args.copy_layer:
+17 -2
View File
@@ -55,7 +55,7 @@ def get_type_of_name(name):
"SF" # Drucktaster
]
prefix = name[0:2]
prefix = name[:2]
if prefix in SpecialKeys:
typ = "Sensor"
@@ -72,6 +72,16 @@ def get_type_of_name(name):
return typ
def get_type_of_name_cfg(name):
prefix = name[:2]
if config_BMK.has_option("Routing-Include", prefix):
return "Sensor"
elif config_BMK.has_option("Routing-Ignore", prefix):
return "Schaltschrankelement"
else:
return "unknown"
def get_attributes_of_insert(insert):
id = ""
ld = dict()
@@ -441,10 +451,15 @@ if __name__ == '__main__':
if args.sensors or args.dists or args.rack:
# Allgemeine Config Laden
config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config.optionxform = lambda option: option # preserve case for letters
config.read(os.path.join(config_dir, "allgemein.cfg"))
# Betriebsmittelkennzeichnungs-Config laden
config_BMK = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config_BMK.optionxform = lambda option: option # preserve case for letters
config_BMK.read(os.path.join(config_dir, "BMK.cfg"))
output_results = dict()