批量DWG文件转dxf(CAD图转dxf)——c#插件实现

此插件可将指定文件夹及子文件夹下的dwg文件批量转为dxf文件。

(使用方法:命令行输入 “netload” 加载插件,然后输入“dwg2dxf”运行,选择文件夹即可。)

 生成dxf在此新建的文件夹路径下,包含子文件夹内的dwg转换生成的dxf,由上图可知,14个dwg转完共计14.78秒,约一秒转一个。

部分代码如下:

 public void DwgToDxf()
 {
     // 弹出对话框选文件夹 遍历文件 创建数据库,读取文件,数据库另存
     DateTime beforDT = System.DateTime.Now;
     Document doc = Application.DocumentManager.MdiActiveDocument;
     FolderBrowserDialog dialog = new FolderBrowserDialog();
     dialog.Description = "请选择dwg文件所在文件夹:";  // 设置对话框的标题
     DialogResult dlgResult = dialog.ShowDialog();
     if (dlgResult == DialogResult.OK)
     {
         int counter = 0;
         string dialogPathName = dialog.SelectedPath;
         // 新文件夹的名称 和 新文件夹路径的名称
         string newFolderName = "DXF_" + DateTime.Now.ToString("yyyyMMdd_HHmm");
         string newFolderPath = Path.Combine(dialogPathName, newFolderName);
         // 检查新文件夹是否已存在
         if (!Directory.Exists(newFolderPath))
         { // 如果不存在,则创建它
             Directory.CreateDirectory(newFolderPath);
         }
         string[] fileNames = Directory.GetFiles(dialogPathName, "*.dwg", SearchOption.AllDirectories);//此行代码为只合并dwg
         foreach (string fileName in fileNames)
         {
             string fullfilename = Path.Combine(newFolderPath, Path.GetFileNameWithoutExtension(fileName) + ".dxf");//getfilename不是全路径,getfile是全路径
             try
             {
                 using (Database tempdb = new Database(false, true)) //创建临时数据库(两个参数:是否创建符号表,不与当前文档关联)
                 {///
                 ///省略部分代码
                 }
                 counter = counter + 1;
                 Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n正在转换第{counter}个......{fullfilename}\n");
             }
             catch (System.Exception)
             {
                 Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n第{counter}个......{fullfilename}出现错误......\n");
             }

             //Application.DocumentManager.MdiActiveDocument.Editor.Regen();//刷新屏幕
             System.Windows.Forms.Application.DoEvents();
             //Application.DocumentManager.MdiActiveDocument.SendStringToExecute("._zoom _e ", true, false, false);

         }
         DateTime afterDT = System.DateTime.Now;
         string totaltime = afterDT.Subtract(beforDT).TotalSeconds.ToString("F3", CultureInfo.InvariantCulture);
        
     }
 }

插件链接:百度网盘 请输入提取码

提取码:联系作者

或直接联系作者↓↓↓

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值