Excel Export in eigene Methode und eigenen Schalter ausgelagert
This commit is contained in:
+35
-23
@@ -43,14 +43,8 @@ def add_polyline(msp, points:Polyline, dxf_attribs):
|
|||||||
def new_dxf(json_file, out_path, dxf_file=False):
|
def new_dxf(json_file, out_path, dxf_file=False):
|
||||||
""" creates a new dxf file with a polyline inside which is created by the given json file
|
""" creates a new dxf file with a polyline inside which is created by the given json file
|
||||||
"""
|
"""
|
||||||
with open(json_file, encoding='utf-8') as fh:
|
print("creating dxf ..")
|
||||||
data = json.load(fh)
|
anlage = model_from_json(json_file)
|
||||||
|
|
||||||
anlage = from_dict(
|
|
||||||
data_class=Polylines,
|
|
||||||
data=data
|
|
||||||
)
|
|
||||||
#print(anlage)
|
|
||||||
|
|
||||||
if dxf_file:
|
if dxf_file:
|
||||||
# bestehende DXF-Datei laden
|
# bestehende DXF-Datei laden
|
||||||
@@ -73,22 +67,26 @@ def new_dxf(json_file, out_path, dxf_file=False):
|
|||||||
add_polyline(msp, pl, dxfattribs)
|
add_polyline(msp, pl, dxfattribs)
|
||||||
|
|
||||||
doc.saveas(out_path)
|
doc.saveas(out_path)
|
||||||
|
print("done")
|
||||||
|
|
||||||
|
def model_from_json(json_file):
|
||||||
|
with open(json_file, encoding='utf-8') as fh:
|
||||||
|
data = json.load(fh)
|
||||||
|
|
||||||
|
anlage = from_dict(
|
||||||
|
data_class=Polylines,
|
||||||
|
data=data
|
||||||
|
)
|
||||||
|
return anlage
|
||||||
|
|
||||||
|
def export_excel(json_file, out_path):
|
||||||
# Hier für Excel Export
|
# Hier für Excel Export
|
||||||
excel_path = out_path.replace(".dxf", "_kabellaengen.xlsx")
|
print("creating excel file ..")
|
||||||
write_excel_from_json(anlage, excel_path)
|
anlage = model_from_json(json_file)
|
||||||
|
write_excel_from_json(anlage, out_path)
|
||||||
|
print("done")
|
||||||
|
|
||||||
|
|
||||||
def check_file_in_work(work_dir, filename):
|
|
||||||
fexists = True
|
|
||||||
if not os.path.exists(filename):
|
|
||||||
mypath = os.path.join(work_dir, filename)
|
|
||||||
if not os.path.exists(mypath):
|
|
||||||
fexists = False
|
|
||||||
else:
|
|
||||||
mypath = filename
|
|
||||||
return (mypath, fexists)
|
|
||||||
|
|
||||||
def write_excel_from_json(anlage:Polylines, outpath:str):
|
def write_excel_from_json(anlage:Polylines, outpath:str):
|
||||||
wb = Workbook()
|
wb = Workbook()
|
||||||
length_summary = defaultdict(int)
|
length_summary = defaultdict(int)
|
||||||
@@ -114,12 +112,23 @@ def write_excel_from_json(anlage:Polylines, outpath:str):
|
|||||||
wb.save(outpath)
|
wb.save(outpath)
|
||||||
|
|
||||||
|
|
||||||
|
def check_file_in_work(work_dir, filename):
|
||||||
|
fexists = True
|
||||||
|
if not os.path.exists(filename):
|
||||||
|
mypath = os.path.join(work_dir, filename)
|
||||||
|
if not os.path.exists(mypath):
|
||||||
|
fexists = False
|
||||||
|
else:
|
||||||
|
mypath = filename
|
||||||
|
return (mypath, fexists)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='draws a dxf file with the given cable coordinates', prog='drawdxf')
|
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('-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('-d', '--dxf', action='store', help='this dxf drawing will be copied and the new layer with the cables will be added', metavar='myfile.dxf')
|
parser.add_argument('-d', '--dxf', action='store', help='this dxf drawing will be copied and the new layer with the cables will be added', metavar='myfile.dxf')
|
||||||
parser.add_argument('-n', '--new', action='store', help='create a new dxf file with cables in it. Name is basename and a timtestamp')
|
parser.add_argument('-n', '--new', action='store', help='create a new dxf file with cables in it. Name is basename and a timestamp')
|
||||||
|
parser.add_argument('-x', '--excel', action='store', help='create a xlsx file with cables data', metavar='allCables.xls')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -147,6 +156,9 @@ if __name__ == '__main__':
|
|||||||
#timestamp = datetime.now().strftime(basename+"_%Y%m%d-%H%M%S.dxf")
|
#timestamp = datetime.now().strftime(basename+"_%Y%m%d-%H%M%S.dxf")
|
||||||
#timestamp = datetime.now().strftime("%Y%m%d-%H%M%S.dxf")
|
#timestamp = datetime.now().strftime("%Y%m%d-%H%M%S.dxf")
|
||||||
out_path = os.path.join(work_dir, args.new)
|
out_path = os.path.join(work_dir, args.new)
|
||||||
|
|
||||||
res_pos = new_dxf(json_path, out_path)
|
res_pos = new_dxf(json_path, out_path)
|
||||||
|
|
||||||
|
if args.excel:
|
||||||
|
excel_path = os.path.join(work_dir, args.excel)
|
||||||
|
export_excel(json_path, excel_path)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user