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)