Add a polyline - issue

Hello,

Since we didn’t manage to linearize text from an existing DXF, we tried to create a new DXF, from scratch and create polylines with 2D and 3D points.
We used the documentation avaiable here Add a polyline|Documentation, our only change in order to compile was to replace CadBaseEntity with CadEntityBase.

The final DXF seems to be corrupted and cannot be open in any CAD editor. We get:
undefined group code 90 for object
invalid or incomplete DXF input – drawing discarded

Could you please have a look at code we used and provide an advice? It’s available below.

Thank you,
Andrei

public static void Test3D(string outputDxfFile)
{
    var cadImage = new CadImage();

    CadPolyline polyline = new CadPolyline();
    polyline.ChildObjects.Add(new Cad3DVertex() { LocationPoint = new Cad3DPoint(-5, -5, 0) });
    polyline.ChildObjects.Add(new Cad3DVertex() { LocationPoint = new Cad3DPoint(-5, 10, 0) });
    polyline.ChildObjects.Add(new Cad3DVertex() { LocationPoint = new Cad3DPoint(20, 10, 0) });
    polyline.ChildObjects.Add(new Cad3DVertex() { LocationPoint = new Cad3DPoint(20, -5, 0) });
    polyline.Flag = CadPolylineFlag.CLOSED_POLY;

    List<CadEntityBase> entities = new List<CadEntityBase>();
    entities.Add(polyline);
    cadImage.Entities = entities.ToArray();
    cadImage.UpdateSize();

    cadImage.Save(outputDxfFile, new DxfOptions
    {
        VectorRasterizationOptions = new CadRasterizationOptions
        {
            PageWidth = 1000,
            PageHeight = 1000
        }
    });
}

public static void Test2D(string outputDxfFile)
{
    var cadImage = new CadImage();

    CadLwPolyline cadLwPolyline = new CadLwPolyline();
    cadLwPolyline.Coordinates = new List<Cad2DPoint>();
    cadLwPolyline.Coordinates.Add(new Cad2DPoint(-5d, -5d));
    cadLwPolyline.Coordinates.Add(new Cad2DPoint(-5d, 10d));
    cadLwPolyline.Coordinates.Add(new Cad2DPoint(20d, 10d));
    cadLwPolyline.Coordinates.Add(new Cad2DPoint(20d, -5d));
    cadLwPolyline.Flag = CadLwPolylineFlag.Closed;
    cadLwPolyline.ConstantWidth = 0.1;
    List<CadEntityBase> entities = new List<CadEntityBase>();
    entities.Add(cadLwPolyline);
    cadImage.Entities = entities.ToArray();
    cadImage.UpdateSize();

    cadImage.Save(outputDxfFile, new DxfOptions
    {
        VectorRasterizationOptions = new CadRasterizationOptions
        {
            PageWidth = 1000,
            PageHeight = 1000
        }
    });
}

@andreimoldovansnapon,
probably, this example is more suitable for the creation of new file, but still not success, unfortunately:

  DxfImage cadImage = new DxfImage();

  CadLwPolyline cadLwPolyline = new CadLwPolyline();
  cadLwPolyline.Coordinates = new List<Cad2DPoint>();
  cadLwPolyline.Coordinates.Add(new Cad2DPoint(-5d, -5d));
  cadLwPolyline.Coordinates.Add(new Cad2DPoint(-5d, 10d));
  cadLwPolyline.Coordinates.Add(new Cad2DPoint(20d, 10d));
  cadLwPolyline.Coordinates.Add(new Cad2DPoint(20d, -5d));
  cadLwPolyline.Flag = CadLwPolylineFlag.Closed;
  cadLwPolyline.ConstantWidth = 0.1;

  cadImage.AddEntity(cadLwPolyline);

  cadImage.Save(outPath, new DxfOptions
  {
      VectorRasterizationOptions = new CadRasterizationOptions
      {
          PageWidth = 1000,
          PageHeight = 1000
      }
  });

We have created CADNET-9661 to look at this case deeper and fix the issue.

@andreimoldovansnapon,
please try whether this example is useful:

string outputDxfFile="3D.dxf";

var dxfImage = new DxfImage();

CadPolyline polyline = new CadPolyline();
polyline.VerticesFollowFlag = 1;
var vertex1 = new Cad2DVertex() { LocationPoint = new Cad3DPoint(20, 0) };
var vertex2 = new Cad2DVertex() { LocationPoint = new Cad3DPoint(40, -40) };
var vertex3 = new Cad2DVertex() { LocationPoint = new Cad3DPoint(60, -40) };
dxfImage.AddEntity(polyline);
dxfImage.AddEntity(vertex1);
dxfImage.AddEntity(vertex2);
dxfImage.AddEntity(vertex3);
CadSeqend seqend = new CadSeqend();
dxfImage.AddEntity(seqend);

//Color example
CadLine lineColor = new CadLine(new Cad3DPoint(0, 0, 0), new Cad3DPoint(-100, 0, 100));
dxfImage.AddEntity(lineColor);
lineColor.ColorId = 15; //ACI color id

//polyline style example
CadPolyline polylineStyle = new CadPolyline();
polylineStyle.VerticesFollowFlag = 1;
polyline.StartWidth = 3;
polyline.EndWidth = 3;
var vertex1Style = new Cad2DVertex() { LocationPoint = new Cad3DPoint(-20, 0) };
var vertex2Style = new Cad2DVertex() { LocationPoint = new Cad3DPoint(-40, -40) };
var vertex3Style = new Cad2DVertex() { LocationPoint = new Cad3DPoint(-60, -40) };
dxfImage.AddEntity(polylineStyle);
dxfImage.AddEntity(vertex1Style);
dxfImage.AddEntity(vertex2Style);
dxfImage.AddEntity(vertex3Style);
CadSeqend seqendStyle = new CadSeqend();
dxfImage.AddEntity(seqendStyle);

dxfImage.Save(outputDxfFile);
1 Like

@oleksii.gorokhovatskyi , thank you very much for your effort on helping us out on this topic.

Regards,
Andrei

1 Like

@andreimoldovansnapon,
we were happy to help :slight_smile: