from typing import List import os import subprocess def convert_dxf_to_dwg(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) script_path = f"{dir_path}/batch.scr" with open(script_path, "w", encoding="ansi") as f: for dxf in dxf_files: f.write("FILEDIA 0\n") f.write(f'_open "{dxf}"\n') 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') f.write("FILEDIA 1\n") f.write(f"_close\n") f.write("_exit ") cmd = rf'"{cad_file_path}" /b "{script_path}"' subprocess.Popen(cmd)