应用netdxf(C#)实现dxf文件读写-4、绘制图形

实现思路:实例化对应图像类,并调用AddEntity方法添加到DxfDocument对象中,最后保存文件。

 

1、绘制多段线

LwPolyline widthLine = new LwPolyline();//新建LwPolyline对象
LwPolylineVertex startVertex = new LwPolylineVertex(new Vector2(0, 0));//新建坐标点1
LwPolylineVertex endVertex = new LwPolylineVertex(new Vector2(10, 10));//新建坐标点2
widthLine.Vertexes.AddRange(new[] {startVertex, endVertex});//给多段线增加坐标点

LwPolyline poly = new LwPolyline();
poly.Vertexes.Add(new LwPolylineVertex(-10, -10));
poly.Vertexes.Add(new LwPolylineVertex(10, -10));
poly.Vertexes.Add(new LwPolylineVertex(10, 10));
poly.Vertexes.Add(new LwPolylineVertex(-10, 10));
poly.Vertexes[2].Bulge = 1;
poly.IsClosed = true;//封闭图形

2、绘制圆

Circle circle = new Circle {Center = new Vector3(0,0,10), Radius = 2};//圆心坐标、半径

3、绘制弧线

Arc arc = new Arc {Center = new Vector3(0,0,10), Radius = 2, StartAngle = 30, EndAngle = 160};//圆心坐标、半径、起始角度、结束角度

4、填充

    private static void ComplexHatch()
        {
            //设置填充样式
            HatchPattern pattern = HatchPattern.Load("hatch\\acad.pat", "ESCHER");
            pattern.Scale = 1.5;
            pattern.Angle = 30;

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(-10, -10));
            poly.Vertexes.Add(new LwPolylineVertex(10, -10));
            poly.Vertexes.Add(new LwPolylineVertex(10, 10));
            poly.Vertexes.Add(new LwPolylineVertex(-10, 10));
            poly.IsClosed = true;//图形需要封闭

            //给封闭图形填充
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>
            {
                new HatchBoundaryPath(new List<EntityObject> {poly})
            };
            Hatch hatch = new Hatch(pattern, boundary, true);

            DxfDocument dxf = new DxfDocument();
            dxf.AddEntity(poly);//添加图形
            dxf.AddEntity(hatch);//添加填充
            dxf.Save("complexhatch.dxf");

            DxfDocument dxf2 = DxfDocument.Load("complexhatch.dxf");
            dxf2.Save("complexhatch2.dxf");
        }

5、块

Block block = new Block("MyBlock");
block.Entities.Add(poly);

Insert insert = new Insert(block);
insert.Position = new Vector3(12,22,4);
insert.Scale = new Vector3(1.25,0.75,1);
insert.Scale = new Vector3(1,2,3);
insert.Rotation = 30;
insert.Normal = new Vector3(1,1,1);


DxfDocument doc = new DxfDocument();
doc.AddEntity(poly);
doc.AddEntity(insert);
List<EntityObject> entities = insert.Explode();
doc.AddEntity(entities);
doc.Save("test.dxf");

Block block = Block.Load(baseBlk.Name + ".dxf", "MyBlock");//从文件中读取块

使用教程:

1、安装或下载netdxf插件

2、引用命名空间

3、读写dxf文件

4、绘制图形

5、图形变换

6、注释和标注

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值