当前位置: 首页 > article >正文

一键批量DWG_DXF文件互转——CAD c#插件实现(dwg转dxf dxf转dwg)

如下图,我们有大量的dwg格式文件需转为dxf格式文件,或大量dxf需要转dwg,可用cad插件一键实现。

 

 

使用方式:

第一步:

CAD命令行输入:netload ,加载此dll插件

第二步:

dwg转dxf:CAD命令行输入:dwg2dxf

dxf转dwg:  CAD命令行输入:dxf2dwg

根据提示选择对应文件夹,即可一键完成格式转换。

附部分代码如下:

        [CommandMethod("dxf2dwg")]
        public static void Dxf2Dwg()
        {
            ConvertFiles("dxf", "dwg", (db, inputFile) => db.DxfIn(inputFile, null), (db, outputFile) => db.SaveAs(outputFile, DwgVersion.Current));
        }

        [CommandMethod("dwg2dxf")]
        public static void Dwg2Dxf()
        {
            ConvertFiles("dwg", "dxf", (db, inputFile) => db.ReadDwgFile(inputFile, FileShare.Read, true, null), (db, outputFile) => db.DxfOut(outputFile, 15, true)); // 使用 AutoCAD 2018 DXF 格式
        }


 if (dlgResult != DialogResult.OK) return;
 string dialogPathName = dialog.SelectedPath;
 string[] fileNames = Directory.GetFiles(dialogPathName, $"*.{inputExtension}");
 if (fileNames.Length == 0)
 {
     System.Windows.Forms.MessageBox.Show($"文件夹内没有{inputExtension}文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     return;
 }
 int counter = 0;

 string newFolderName = $"{outputExtension.ToUpper()}_{DateTime.Now:yyyyMMdd_HHmm}";
 string newFolderPath = Path.Combine(dialogPathName, newFolderName);

 if (!Directory.Exists(newFolderPath))
 {
     Directory.CreateDirectory(newFolderPath);
 }

 foreach (string fileName in fileNames)
 {
     string fullfilename = Path.Combine(newFolderPath, Path.GetFileNameWithoutExtension(fileName) + $".{outputExtension}");
}

 插件作者↓↓↓


http://www.kler.cn/a/592729.html

相关文章:

  • 物联网为什么用MQTT不用 HTTP 或 UDP?
  • 关于QMetaObject::invokeMethod的作用和用法
  • 2025火狐插件被禁用解决方案 could not be verified for use in Firefox and has been disabled
  • php 高性能,高并发,有哪些框架,扩展,推荐一下,或者技术的实现有哪些
  • Weblogic未授权远程命令执行漏洞复现
  • 【内付相关主题会议进行参考】智能技术应用前沿:算法、感知与控制的学术支点与产业衔接
  • 配置固定ip绕过ip限制
  • 动平衡仿真程序设计
  • JVM 的类加载机制原理
  • Flask应用调试模式下外网访问的技巧
  • 类和对象C++
  • keepalived应用
  • 2025年【安全员-C证】新版试题及安全员-C证理论考试
  • HTTP请求方法详解:GET、POST、PUT在微信小程序中的应用
  • milvus实战-基于Ollama+bge-large-zh搭建嵌入模型,fastAPI提供http服务将PDF文件写入milvus向量库
  • Java 文件和IO流基础(生动形象版)
  • jmeter中,上传文件的MIME类型
  • pnpm config set ignore-workspace-root-check true
  • CSS三大特性、显示模式、背景与书写顺序
  • AI赋能生态学:ChatGPT+多技术融合在生态系统服务中的实践探索与学术写作