Merge branch 'main' of http://gitea.schoenenberger.de/mistangl/kabellaengen
This commit is contained in:
+41
-25
@@ -36,7 +36,7 @@ def add_polyline(msp, points:Polyline, dxf_attribs):
|
||||
pline = msp.add_lwpolyline(points=pts, dxfattribs=dxf_attribs)
|
||||
pline.rgb = (255, 128, 0)
|
||||
|
||||
def new_dxf(json_file, dxf_file, out_path):
|
||||
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
|
||||
"""
|
||||
with open(json_file, encoding='utf-8') as fh:
|
||||
@@ -48,12 +48,12 @@ def new_dxf(json_file, dxf_file, out_path):
|
||||
)
|
||||
#print(anlage)
|
||||
|
||||
# Create a new drawing in the DXF format of AutoCAD 2010
|
||||
#doc = ezdxf.new('R2018', setup=True)
|
||||
|
||||
# 1. Bestehende DXF-Datei laden
|
||||
doc = ezdxf.readfile(dxf_file)
|
||||
msp = doc.modelspace()
|
||||
if dxf_file:
|
||||
# bestehende DXF-Datei laden
|
||||
doc = ezdxf.readfile(dxf_file)
|
||||
else:
|
||||
# neue Zeichnung im DXF format of AutoCAD 2010
|
||||
doc = ezdxf.new('R2018', setup=True)
|
||||
|
||||
# 2. Layer mit Zeitstempel erstellen (z. B. "Layer_2025-05-07_14-30")
|
||||
timestamp = datetime.now().strftime("Kabel_%Y-%m-%d_%H-%M")
|
||||
@@ -70,34 +70,50 @@ def new_dxf(json_file, dxf_file, out_path):
|
||||
|
||||
doc.saveas(out_path)
|
||||
|
||||
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__':
|
||||
parser = argparse.ArgumentParser(description='draws a dxf file with the given cable coordinates', prog='drawdxf')
|
||||
parser.add_argument('-j', '--jsonfile', 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', required=True, 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_true', help='create a new dxf file with cables in it. Name is basename and a timtestamp')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
work_dir = os.fspath(os.environ.get('PROJECT_WORK'))
|
||||
jfile = args.jsonfile
|
||||
dxf_file = args.dxf
|
||||
(json_path, jexists) = check_file_in_work(work_dir, jfile)
|
||||
if not jexists:
|
||||
print("file %s does not exit", jfile)
|
||||
parser.print_help()
|
||||
exit()
|
||||
|
||||
if args.jsonfile and args.dxf:
|
||||
jpath = os.path.join(work_dir, os.fspath(jfile))
|
||||
dxf_path = os.path.join(work_dir, os.fspath(dxf_file))
|
||||
|
||||
if not os.path.exists(jpath):
|
||||
print("file %s does not exit", jpath)
|
||||
if args.dxf:
|
||||
# falls ein neuer Layer hinzu gefügt werden soll
|
||||
dxf_file = args.dxf
|
||||
(dxf_path, dexists) = check_file_in_work(work_dir, dxf_file)
|
||||
if not dexists:
|
||||
print("file %s does not exit", dxf_file)
|
||||
parser.print_help()
|
||||
exit()
|
||||
if not os.path.exists(dxf_path):
|
||||
print("file %s does not exit", dxf_path)
|
||||
exit()
|
||||
|
||||
basename = os.path.splitext(dxf_path)[0]
|
||||
timestamp = datetime.now().strftime(basename+"_%Y%m%d-%H%M%S.dxf")
|
||||
out_path = dxf_path
|
||||
res_pos = new_dxf(json_path, out_path, dxf_file=dxf_path)
|
||||
else:
|
||||
# erzeuge eine neue dxf Datei mit aktuellen Zeitstempel im Namen
|
||||
#basename = os.path.splitext(dxf_path)[0]
|
||||
#timestamp = datetime.now().strftime(basename+"_%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, timestamp)
|
||||
|
||||
# erzeuge eine neue dxf Datei mit aktuellen Zeitstempel im Namen
|
||||
res_pos = new_dxf(jpath, dxf_path, out_path)
|
||||
else:
|
||||
parser.print_help()
|
||||
res_pos = new_dxf(json_path, out_path)
|
||||
|
||||
Reference in New Issue
Block a user