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: f.write("FILEDIA 0\n") for ind, dxf in enumerate(dxf_files): 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') if ind == len(dxf_files) - 1: f.write("FILEDIA 1\n") # 最后一个回复打开dialog f.write("qquit\n") else: f.write(f"_close\n") # f.write("qquit\n") cmd = rf'"{cad_file_path}" /b "{script_path}"' subprocess.Popen(cmd)