admin管理员组文章数量:1604751
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二次开发。
第一种方式比较直接,但对版本号有要求。
第二种也是笔者采用的方法,比较简单,官网也有教程,通俗易懂。
第三种看似简单,但是找不到匹配的库,未采用。
第四种与我的需求不符,但是是最常用的方法,网上资料也最多。
版权声明:本文标题:导出CAD文件的几种方法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728463027a1159165.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论