导出CAD文件的几种方法

1. 直接导入COM组件里的AutoCAD的dll。

private void Write()
        {
            a = new AcadApplicationClass();
            a.Visible = true;

            var p = a.ActiveDocument.ModelSpace;
            
            p.AddBox(new double[] { 0, 0, 0 }, 200, 200, 1);
            p.AddCircle(new double[] { 100, 100, 1 }, 100);
            var pts = VirtualPoints();


            for (int i = 0; i < pts.Count; i++)
            {
                bool hasException;
                do
                {
                    try
                    {
                        p.AddBox(new double[] { pts.ElementAt(i).X, pts.ElementAt(i).Y, 0 }, 10, 10, 1);
                        hasException = false;
                    }
                    catch (System.Runtime.InteropServices.COMException e)
                    {
                        if (e.ErrorCode == -2147418111)
                        {
                            hasException = true;
                        }
                        else
                        {
                            throw;
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                } while (hasException);
            }
            if (a.ActiveDocument.Saved == false)
            {
                a.ActiveDocument.SaveAs("F:\\Wafer_Sort\\image.dwg", AcSaveAsType.ac2018_dwg, null);

            }



        }

2. 利用netdxf的库进行开发。

public static void Main()
{
	// your DXF file name
	string file = "sample.dxf";

	// create a new document, by default it will create an AutoCad2000 DXF version
	DxfDocument doc = new DxfDocument();
	// an entity
	Line entity = new Line(new Vector2(5, 5), new Vector2(10, 5));
	// add your entities here
	doc.Entities.Add(entity);
	// save to file
	doc.Save(file);

	// this check is optional but recommended before loading a DXF file
	DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file);
	// netDxf is only compatible with AutoCad2000 and higher DXF versions
	if (dxfVersion < DxfVersion.AutoCad2000) return;
	// load file
	DxfDocument loaded = DxfDocument.Load(file);
}

3. 收集资料得到(未尝试)

private void ExportCad()
        {
            using (Services svcs = new Services())
            {
                Database db = new Database();
                Circle cirl = new Circle();
                cirl.Center = new Point3d(100, 100, 0);
                cirl.Radius = 14;
                BlockTableRecord btr = (BlockTableRecord)db.CurrentSpaceId.Open(OpenMode.ForWrite);

                btr.AppendEntity(cirl);
                db.SaveAs("C:\\test.dwg", DwgVersion.Current);

            }




        }

4. 利用CAD二次开发。

第一种方式比较直接,但对版本号有要求。

第二种也是笔者采用的方法,比较简单,官网也有教程,通俗易懂。

第三种看似简单,但是找不到匹配的库,未采用。

第四种与我的需求不符,但是是最常用的方法,网上资料也最多。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"ad导出cad显示没有注册类"这个问题,是指在AutoCAD软件中使用AD命令导入或转换AutoCAD图纸的过程中出现了无法注册类的错误提示。 出现这个问题的原因可能有以下几种情况: 1. AutoCAD版本不兼容:AD命令可能来自于AutoCAD的不同版本,并且与当前使用的AutoCAD版本不兼容。解决方法是检查AD命令的版本并尝试在相应的AutoCAD版本中运行。 2. 未正确加载AD插件:有时,AD命令需要特定的插件或扩展来正确运行。在这种情况下,需要加载并注册相应的AD插件。可以通过在AutoCAD中运行命令"NETLOAD"来加载插件,然后使用"REGISTER"命令来注册插件。 3. 安装错误或文件缺失:有可能在安装过程中出现了错误,或者相关的AD文件丢失。要解决这个问题,需要重新安装AD命令或修复已安装的AutoCAD软件。 4. 缺乏必要的环境变量:AD命令可能需要特定的环境变量设置才能正常运行。您可以检查AutoCAD配置文件中的环境变量设置,并根据需要进行修改。 在解决这个问题之前,建议您进行以下操作: 1. 确保AutoCAD软件已经更新到最新版本,并且与AD命令的版本兼容。 2. 检查AD命令的文档或官方网站,查看是否有特殊的安装要求或建议。 3. 在网络或AutoCAD社区中搜索类似的问题,看看其他用户是如何解决的。 总之,要解决"ad导出cad显示没有注册类"的问题,您可以尝试调整AutoCAD版本兼容性、加载和注册插件、重新安装AutoCAD软件、修改环境变量设置等方法。如果问题仍然存在,建议您联系AutoCAD的技术支持部门或寻求专业的AutoCAD咨询和帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值