1

Resolved

Error when loading Spline created with only Fit Points

description

I need to replace all the closed splines in a DXF with open splines and lines that close them (this is required by a nesting engine I'm working with).
To do so I want to change a closed Spline guided by Control Points into an open Spline guided by Fit Points.
To do so I used the method ToPolyline to have points on the spline and then create a new spline with those points as Fit Points (I also add a Line into the DXF to close the new spline).
Then I replace the old spline (Control Points driven) with the new spline (Fit Points driven) inside the DXF.

code:

int precision = 10 * spline.Knots.Count();
                    //precision = 100;
                    Polyline polyline = spline.ToPolyline(precision);
                    Line fixLine = new Line();

                    if (polyline.Vertexes.Count >= 2)
                    {
                        fixLine.StartPoint = new Vector3(polyline.Vertexes[0].Position.X, polyline.Vertexes[0].Position.Y, 0);
                        fixLine.EndPoint = new Vector3(polyline.Vertexes[polyline.Vertexes.Count - 1].Position.X, polyline.Vertexes[polyline.Vertexes.Count - 1].Position.Y, 0);

                        fixLine.Linetype = netDxf.Tables.Linetype.Continuous;
                        fixLine.IsVisible = true;
                        fixLine.Color = new AciColor(spline.Color.ToColor());
                        fixLine.Lineweight = spline.Lineweight;

                        fixLine.Layer = spline.Layer;
                        splineToRemove = spline;

                        List<Vector3> fitPoints = new List<Vector3>();
                        foreach (PolylineVertex vert in polyline.Vertexes) //.Take(polyline.Vertexes.Count - 1))
                        {
                            fitPoints.Add(new Vector3(vert.Position.X, vert.Position.Y, 0));
                        }
                        //mySpline = new Spline(splineVertex, knots, spline.Degree);
                        mySpline = new Spline(fitPoints);

                        count++;
                        dxfDocument.AddEntity(fixLine);
                    }


            dxfDocument.RemoveEntity(splineToRemove);
            dxfDocument.AddEntity(mySpline);

The problem is that when the DXF with the new spline is loaded by DxfDocument (DxfDocument.Load) it raises an error:
The number of control points must be equal or greater than 2.

This error is raised by both version 2.00 and 2.02 of NetDXF dll.

My guess is that this is a bug or maybe my new spline isn't created correctly.
Could you give me any suggestion?

comments

haplokuon wrote Feb 17 at 2:34 PM

I will fix it.

Since AutoCad always saves the splines with the fit points and the control points, the load code was expecting them, but it is actually enough with one set of those points. You can create an Spline with fit points but it will not calculate the control points for the resulting curve. So only the fit points are saved, but the load was also expecting the control points, and since there is none an error is raised.

Daniel