78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
import argparse
|
|
import configparser
|
|
import ezdxf
|
|
import os
|
|
import sys
|
|
|
|
"""
|
|
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 the x/y positions from a dxf file', prog='getpositions')
|
|
parser.add_argument('-f', '--filename', action='store', default="ST_6300_Steuerungstestlayout1_neueBloecke.dwg", help='which file should be fetched', metavar='myfile.dwg')
|
|
parser.add_argument('-i', '--input', action='store_true', help='fetch all position of inputs')
|
|
parser.add_argument('-o', '--output', action='store_true', help='fetch all positions of outputs')
|
|
parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks')
|
|
|
|
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(work_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()
|