Erdungskabel und Erdungen werden gesucht und ein Kabellayout erzeugt

This commit is contained in:
2025-06-25 11:14:40 +02:00
parent ee9f1b8dae
commit 371fe6241e
5 changed files with 64 additions and 16 deletions
+34 -15
View File
@@ -1,16 +1,13 @@
import argparse
import configparser
import ezdxf.document
from ezdxf import readfile
import ezdxf
import os
import sys
import json
import re
from shapely import Point
from itertools import combinations
from ezdxf.addons import iterdxf
import re
import time
from pathlib import Path
"""
@@ -97,6 +94,11 @@ def get_attributes_of_insert(insert):
#print(f"Attribut Name: {attrib.dxf.tag}, Wert: {attrib.dxf.text}")
ld[attr_tag] = attr_text
if attr_tag == "NAME": # die neueren Bläcke heissen nicht IO, sondern haben einen Namen
typ = get_type_of_name_cfg(attr_text)
id = attr_text
# 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))
if attr_tag == "IO":
typ = get_type_of_name_cfg(attr_text)
id = attr_text
@@ -389,11 +391,12 @@ def get_dxf_file(filepath):
sys.exit(2)
return doc
def check_file_in_work(work_dir, filename):
def check_file_in_work(work_dir:Path, filename:Path):
fexists = True
if not os.path.exists(filename):
mypath = os.path.join(work_dir, filename)
if not os.path.exists(mypath):
if not filename.exists(): # dann schau im Work Ordner nach
mypath = work_dir.joinpath(filename)
ex = mypath.exists()
if not mypath.exists():
fexists = False
else:
mypath = filename
@@ -455,6 +458,14 @@ def validate_configs():
else:
print ("No inconsistencies found")
def check_environment_var(env_str:str) -> Path:
out_path = os.environ.get(env_str)
if out_path:
return Path(out_path)
else:
print(f"Umgebungsvariable {env_str} ist nicht gesetzt oder leer.")
exit()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='fetches the x/y positions from a dxf file', prog='getpositions')
@@ -467,13 +478,21 @@ if __name__ == '__main__':
args = parser.parse_args()
out_dir = os.environ.get('PROJECT_DATA')
work_dir = os.environ.get('PROJECT_WORK')
config_dir = os.environ.get("PROJECT_CFG")
filename = args.filename
(dxf_path, dexists) = check_file_in_work(work_dir, filename)
out_dir = check_environment_var('PROJECT_DATA')
work_dir = check_environment_var('PROJECT_WORK')
config_dir = check_environment_var("PROJECT_CFG")
filename = Path(args.filename)
if not filename.suffix == ".dxf":
print("only available for .dxf files")
exit()
(dxf_path, dexists) = check_file_in_work(work_dir, filename)
if dexists == False:
print("no such file ")
parser.print_help()
exit()
if dxf_is_binary(dxf_path): # Wenn dxf eine binary ist, dann komplett parsen und modelspace anlegen
print("Given .dxf-file is binary dxf. Proceeding to read file. Watch RAM-usage.")
doc = get_dxf_file(dxf_path)