erste Config dazu. Erste Version von getpositions mit Argumentparser erstellt

This commit is contained in:
2025-04-28 10:37:30 +02:00
parent 1da1db5098
commit 376a3da86a
2 changed files with 85 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
[Eingänge]
0-0_ILS_EINGANG
[Ausgänge]
AUSGANG
MOTOR
[Pritsche]
PRITSCHE_100-60-SCHRAFF
+76
View File
@@ -0,0 +1,76 @@
import argparse
import configparser
import ezdxf
import os
"""
Dieses Programm:
- liest die dxf Datei und holt sich von den Layern der dxf Datei die Positionen
+ der Motoren, Sensoren und Aktoren
+ der Unterverteiler
+ der Polylinien der Kabelpritschen
- erzeugt daraus eine .json Datei im Work Ordner
"""
def write_results(jsnResults, outdir, filename):
""" write results to a json file
"""
print("writing results to a json file ...")
outfile = os.path.join(outdir, filename)
with open(outfile, 'w', encoding='utf-8') as fh:
fh.write(jsnResults)
print("done")
def get_input_positions(doc):
"""hole alle Positionen der Eingänge
"""
pass
def get_output_positions(doc):
"""hole alle Positionen der Ausgänge
"""
pass
def get_rack_positions(doc):
"""hole alle Positionen aller Kabelpritschen
"""
pass
def get_dxf_file(filepath):
"""hole das dxf file
"""
try:
doc = ezdxf.readfile(filepath)
except IOError:
print(f"Not a DXF file or a generic I/O error.")
sys.exit(1)
except ezdxf.DXFStructureError:
print(f"Invalid or corrupted DXF file.")
sys.exit(2)
return doc
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='fetches positions from a dxf file', prog='get_positions')
parser.add_argument('-f', '--filename', action='store', required=True, default="ST_6300_Steuerungstestlayout1_neueBloecke.dwg", help='which file should be fetched', metavar='file')
parser.add_argument('-i', '--input', action='store_true', help='fetch all position of inputs', metavar='input')
parser.add_argument('-o', '--output', action='store_true', help='fetch all positions of outputs', metavar='output')
parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks', metavar='output')
args = parser.parse_args()
out_dir = os.environ.get('PROJECT_DATA')
work_dir = os.environ.get('PROJECT_WORK')
filename = args.filename
doc = get_dxf_file(os.path.join(out_dir, filename))
res = dict()
if args.input:
res = get_input_positions(doc)
if args.output:
get_input_positions(doc)
if args.rack:
get_input_positions(doc)
else:
parser.print_help()