From 8c60899f8edc18c71b13e493f41ae362aac5067e Mon Sep 17 00:00:00 2001 From: n3040 Date: Wed, 31 Jan 2024 14:29:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=BA=E9=87=87=E7=94=A8ac?= =?UTF-8?q?coreconsole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cad.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cad.py b/cad.py index ca11b21..641bad9 100644 --- a/cad.py +++ b/cad.py @@ -3,7 +3,24 @@ import os import subprocess + def convert_dxf_to_dwg(dxf_files: List[str]): + cad_file_path = r"D:/Program Files/Cad2022/AutoCAD 2022/accoreconsole.exe" + first_dwg_file = dxf_files[0] + dir_path = os.path.dirname(first_dwg_file) + script_path = f"{dir_path}/batch.scr" + for _, dxf in enumerate(dxf_files): + with open(script_path, "w", encoding="ansi") as f: + file_name_path, _ = os.path.splitext(dxf) + new_dwg_name = f"{file_name_path}.dwg" + if os.path.exists(new_dwg_name): + os.remove(new_dwg_name) + f.write(f'saveas 2004 "{new_dwg_name}"\n') + cmd = rf'"{cad_file_path}" /s "{script_path}" /i "{dxf}" /iso' + subprocess.call(cmd,stderr=subprocess.DEVNULL,stdin=subprocess.DEVNULL,stdout=subprocess.DEVNULL) + + +def convert_dxf_to_dwg1(dxf_files: List[str]): cad_file_path = r"D:/Program Files/Cad2022/AutoCAD 2022/acad.exe" first_dwg_file = dxf_files[0] dir_path = os.path.dirname(first_dwg_file)