From e5d6ed5d96673056c9ca1527f8d2a6f77938667c Mon Sep 17 00:00:00 2001 From: lertlmaier Date: Wed, 21 May 2025 12:55:27 +0200 Subject: [PATCH] Launch.json angepasst, sodass draw cable dxf from easy to new dxf ein neues dxf mit namen easy_cables schriebt. getexdraw.bat angepasst, sodass bei routing ein graph angezeigt wird und gespeichert werden kann (testweise). drawdxf.py angepasst, sodass eine excel ausgabe mit 2 Worksheets geschrieben wird. --- .vscode/launch.json | 3 ++- bin/getexdraw.bat | 4 ++-- lib/drawdxf.py | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d92ba04..5d4815d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -91,7 +91,8 @@ "args": [ "--json", "easy.json", - "--new" + "--new", + "easy_cables" ] }, { diff --git a/bin/getexdraw.bat b/bin/getexdraw.bat index 9b7128a..1fb0816 100644 --- a/bin/getexdraw.bat +++ b/bin/getexdraw.bat @@ -1,4 +1,4 @@ -@echo off +REM @echo off if [%1]==[] goto usage for /F %%i in ("%1") do set FILENAME=%%~ni @@ -6,7 +6,7 @@ for /F %%i in ("%1") do set FILENAME=%%~ni echo --hole Positionen call getpositions.bat --filename %1 -s -r -w %1 echo --erzeuge Graph mit Routing -call routing.bat --filename %FILENAME%.json -w todraw.json +call routing.bat --filename %FILENAME%.json -w todraw.json -g echo --zeichne Kabel in dxf Datei call draw_dxf.bat --filename todraw.json --new %FILENAME%_cables.dxf diff --git a/lib/drawdxf.py b/lib/drawdxf.py index 972d7cb..a94a7bb 100644 --- a/lib/drawdxf.py +++ b/lib/drawdxf.py @@ -5,7 +5,10 @@ import os.path from dataclasses import dataclass, asdict, fields from dacite import from_dict from typing import List -from datetime import datetime +from datetime import datetime +from openpyxl import Workbook +import math +from collections import defaultdict @@ -19,6 +22,7 @@ class Point: class Polyline: id: str coords: List[Point] + length: float def to_tuple(self): ret = list() @@ -70,6 +74,11 @@ def new_dxf(json_file, out_path, dxf_file=False): doc.saveas(out_path) + # Hier für Excel Export + excel_path = out_path.replace(".dxf", "_kabellaengen.xlsx") + write_excel_from_json(anlage, excel_path) + + def check_file_in_work(work_dir, filename): fexists = True if not os.path.exists(filename): @@ -80,6 +89,30 @@ def check_file_in_work(work_dir, filename): mypath = filename return (mypath, fexists) +def write_excel_from_json(anlage:Polylines, outpath:str): + wb = Workbook() + length_summary = defaultdict(int) + + #Worksheet 1 - Kabellängen + ws1 = wb.active + ws1.title = "Kabellängen" + ws1.append(["Kabel-ID", "Länge aus Json (m)", "Gerundete Länge (m)"]) + + for pl in anlage.kabel: + length = pl.length /1000 # Umrechnung von mm in m + rounded_len = math.ceil(length/10)*10 + length_summary[rounded_len] +=1 + ws1.append([pl.id, length, int(rounded_len)]) + + # Worksheet 2 - Zusammengefasste Längen + ws2 = wb.create_sheet("Längenübersicht") + ws2.append(["Gerundete Länge (m)", "Anzahl Kabel"]) + + for rlength in sorted(length_summary): + ws2.append([int(rlength), length_summary[rlength]]) + + wb.save(outpath) + if __name__ == '__main__':