DomCR / ACadSharp

C# library to read/write cad files like dxf/dwg.
MIT License
432 stars 119 forks source link

LwPolyline is always closed, Polyline2d.Vertices cannot set Bulge, and Dxf opening in CAD Error #174

Closed TzhongWei closed 9 months ago

TzhongWei commented 1 year ago

I tried to create some polylines into a dxf file with the given file path. Because IsClosed defined with IPolyline was readonly, I used LwPolylineFlags to set the LwPolyline closed. However, after trying three options of them, none of them is opened polyline. Please, have a look at the first function. Secondly, I created a polyline2D with setting Bulge at one of its vertices. The arc cannot be set up with it. Both bugs, I've checked in debugs mode, were correct, while in the AutoCAD they didn't match my setting. Besides, whenever I opened the dxf file. AutoCAD always opened the file twice and showed it was readonly. Was it correct? //Program 1 public static void DrawLwPolylineTest(string input) { CadDocument doc = new CadDocument();

        List<LwPolyline.Vertex> vertices = new List<LwPolyline.Vertex>() {
            new LwPolyline.Vertex(new XY(0,0)),
        new LwPolyline.Vertex(new XY(1,0)),
        new LwPolyline.Vertex(new XY(2,1)),
        new LwPolyline.Vertex(new XY(3,1)),
        new LwPolyline.Vertex(new XY(4,4))
        };

        var LwPline = new LwPolyline();

        for (int i = 0; i < vertices.Count; i++)
            LwPline.Vertices.Add(vertices[i]);
        LwPline.Flags = LwPolylineFlags.Default;

        LwPline.Vertices[2].Bulge = -0.5;
        doc.Entities.Add(LwPline);
        using (var writer = new DxfWriter(input, doc, true))
        {
            writer.OnNotification += NotificationHelper.LogConsoleNotification;
            writer.Write();
        }
    }

//Program 2 public static void DrawPolylineTest(string input) { CadDocument doc = new CadDocument(); List vector2d = new List(){ new Vertex2D(){Location = new XYZ(0,0,0)}, new Vertex2D(){Location = new XYZ(1,0,0)}, new Vertex2D(){Location = new XYZ(2,1,0)}, new Vertex2D(){Location = new XYZ(3,1,0)}, new Vertex2D(){Location = new XYZ(4,4,0)} };

        var Pline = new Polyline2D();
        Pline.Vertices.AddRange(vector2d);
        Pline.Flags = PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM;
        Pline.Vertices.ElementAt(3).Bulge = 1;

        doc.Entities.Add(Pline);
        using (var writer = new DxfWriter(input, doc, true))
        {
            writer.OnNotification += NotificationHelper.LogConsoleNotification;
            writer.Write();
        }

    }
DomCR commented 1 year ago

Hi @TzhongWei,

I'll test this issue on my end and open a branch to address it, thanks for the feedback.

About the read only, this seems to be an issue with the way that you are opening the file, I haven't encounter this kind of issue on any machine, make sure that your debugger is stopped and all the streams are properly disposed, maybe the file is opened for some other process.