netDxf实现对cad文件的读取与写入

工程项目中CAD作为常用的设计软件

有大量的设计数据及信息需要在项目中使用,通过C#的netDxf reader读取cad文件的元数据

github地址:

GitHub - haplokuon/netDxf: .net dxf Reader-Writer

代码示例:

写入dxf

    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);
    }

读取dxf

public static void Main()
    {

        // your DXF file name
        String file = "sample.dxf";

        bool isBinary;
        DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file, out isBinary);

        // check if the file is a dxf
        if (dxfVersion == DxfVersion.Unknown)
        {
            Console.WriteLine("THE FILE {0} IS NOT A VALID DXF OR THE DXF DOES NOT INCLUDE VERSION INFORMATION IN THE HEADER SECTION", file);
            Console.WriteLine();
            return null;
        }

        // check if the dxf file version is supported
        if (dxfVersion < DxfVersion.AutoCad2000)
        {
            Console.WriteLine("THE FILE {0} IS NOT A SUPPORTED DXF", file);
            Console.WriteLine();

            Console.WriteLine("FILE VERSION: {0}", dxfVersion);
            Console.WriteLine();
            return null;
        }

        DxfDocument dxf = DxfDocument.Load(file);

        var LwPolylines = dxf.LwPolylines.ToList();

        Console.WriteLine("多段线条数:" + LwPolylines.Count);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值