批量DWG文件转换低版本(CAD图转低版本)——c#插件实现

        此插件可实现指定路径下所有dwg文件(包含子文件夹内dwg)一键全部转为低版本(包含2004、2007、2018版本,也可定制指定版本)。效果如下:

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

附部分代码:

 public void Dwg2007()
 {
     DateTime beforDT = System.DateTime.Now;
     Database currentdb = HostApplicationServices.WorkingDatabase;
     FolderBrowserDialog dialog = new FolderBrowserDialog();
     dialog.Description = "请选择dwg文件所在文件夹:";  // 设置对话框的标题
     DialogResult dlgResult = dialog.ShowDialog();
     if (dlgResult == DialogResult.OK)
     {
         int counter = 0;
         string pathName = dialog.SelectedPath;
         // 新文件夹的名称 和 新文件夹路径的名称
         string newFolderName = "DWG_2007_" + DateTime.Now.ToString("yyyyMMdd_HHmm");
         string newFolderPath = Path.Combine(pathName, newFolderName);
         // 检查新文件夹是否已存在
         if (!Directory.Exists(newFolderPath))
         { // 如果不存在,则创建它
             Directory.CreateDirectory(newFolderPath);
         }
         string[] fileNames = Directory.GetFiles(pathName, "*.dwg", SearchOption.AllDirectories);//此行代码为只合并dwg
         foreach (string fileName in fileNames)
         {
             string fullfilename = Path.Combine(newFolderPath, Path.GetFileName(fileName));//getfilename不是全路径,getfile是全路径

             try
             {
                 using (Transaction tr = currentdb.TransactionManager.StartTransaction())
                 {//当前数据库开启事务
                    //
                    //省略部分代码
                     counter = counter + 1;
                     tr.Commit();
                 }
                 Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n正在转换第{counter}个......{fullfilename}\n");
             }
             catch (System.Exception)
             {
                 Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n出现错误......\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、付费专栏及课程。

余额充值