netdxf介紹github庫
https://github.com/haplokuon/netDxf
netDxf是一個.net庫,用C語言編程,用於讀取和寫入AutoCAD DXF文件。它支持文本和二進制格式的AutoCad2000、AutoCad2004、AutoCad2007、AutoCad2010、AutoCad2013和AutoCAD2018DXF數據庫版本。
這個庫很容易使用,我盡量使過程簡單明了,例如,您不需要用圖層、樣式或線型定義填充表格部分。每次添加新項時,DxfDocument都會處理這個問題。
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.AddEntity(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); }
支持的實體
- 3dFace
- Arc
- Circle
- Dimensions (aligned, linear, radial, diametric, 3 point angular, 2 line angular, and ordinate)
- Ellipse
- Hatch (including Gradient patterns)
- Image
- Insert (block references and attributes)
- Leader
- Line
- LwPolyline (light weight polyline)
- Mesh
- MLine
- MText
- Point
- PolyfaceMesh
- Polyline
- Ray
- Shape
- Solid
- Spline
- Text
- Tolerance
- Trace
- Underlay (DGN, DWF, and PDF underlays)
- Wipeout
- XLine (aka construction line)
所有實體都可以分組。所有DXF對象都可能包含擴展數據信息。AutoCad表格圖元將作為插入(塊參照)導入。支持簡單線型和復雜線型。庫永遠無法讀取某些實體,如面域、曲面和三維實體,因為它們依賴於未記錄的專有數據。