DXF Export of Polylines in BCB6

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
Richard Wissler
Posts: 7
Joined: 15 Apr 2005, 20:08

DXF Export of Polylines in BCB6

Post by Richard Wissler » 05 Jul 2007, 17:53

Hello,

I have problems in writing polylines to dxf. Possible a very simple and silly error.

I am doing the following:

Code: Select all


  if (SaveDialog1->Execute())
  {
    TdxfExportData D;
    TdxfPoint *Pt;
    TsgDXFExport *E = new TsgDXFExport();
    double x,y;

    try
    {
      E->Millimetres = true;
      D.Color = 1;

      for (int i=0; i<view.nShapes; i++)
      {
        if (view.oShapes[i].GetCount() > 2)
        {
          D.Points = new TList();
          for (int j=0; j<view.oShapes[i].GetCount(); j++)
          {
            Pt = new TdxfPoint();
            view.oShapes[i].GetPoint(j, x, y);
            Pt->X = x*1000;
            Pt->Y = y*1000;

            D.Points->Add(Pt);
          }

          E->AddPolyLine(D,0);
        }
      }

      E->EndDraw();
      E->SaveToFile(SaveDialog1->FileName);
    }
    __finally
    {
      delete E;
      delete D.Points;
    }
  }
When debugging, everything seems to work but SaveToFile results in an error.

What am I doing wrong?

Best regards
Richard

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 06 Jul 2007, 13:45

Hello Richard!

Please try the following code:

Code: Select all

<b>void __fastcall</b> TfmDXFExporter::AddPolylineClick(TObject *Sender)
{
  TsgDXFExport *E = <b>new</b> TsgDXFExport();
  TdxfExportData Data;
  PexpPoint Pt;
  TList *vList;
  <b>float</b> * Array = <b>new float</b>[2];

  E->AutoCADVer = R2000;
  E->Millimetres = <b>true</b>;

  memset(Array, 0, <b>sizeof</b>(Array) * <font color="blue">2</font id="blue">);
  Array[<font color="blue">0</font id="blue">] = <font color="blue">5</font id="blue">;
  Array[<font color="blue">1</font id="blue">] = <font color="blue">0</font id="blue">;
  E->AddLType(<font color="blue">"_SOLID"</font id="blue">, Array, <font color="blue">2</font id="blue">);

  memset(&Data, <font color="blue">0</font id="blue">, <b>sizeof</b>(TdxfExportData));
  Data.Text = <font color="blue">"_SOLID"</font id="blue">;
  Data.Color = ColorToDXF(TColor(0x224AF5));
  Data.GlobalWidth = <font color="blue">2</font id="blue">;<font color="blue"><i>// Constant width DXF code 43</i></font id="blue">
  Data.Points = <b>new</b> TList();
  Data.Points->Add(<b>new</b> TList());

  <b>try</b>
  {
    vList = (TList *)(Data.Points->Items [<font color="blue">0</font id="blue">]);
    <b>for</b> (<b>int</b> i=<font color="blue">0</font id="blue">;i<<font color="blue">12</font id="blue">;i++)
    {
      Pt = <b>new</b> TexpPoint();
      *Pt = MakeExpPoint(i*<font color="blue">10</font id="blue">, sqrt(i)*<font color="blue">20</font id="blue">, <font color="blue">0</font id="blue">);
      vList->Add(Pt);
    }
    Data.Count = vList->Count;
    E->AddPolyLine(Data, 0);
    E->SaveToFile(<font color="blue">"c:\\Polyline.dxf"</font id="blue">);
  }
  <b>__finally</b>
  {
    <b>delete</b>[] Array;
    <b>delete</b> E;
  }
}
BTW: <i>TsgDXFExport.EndDraw</i> is necessary only if TsgDXFExport.Canvas was called.

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Richard Wissler
Posts: 7
Joined: 15 Apr 2005, 20:08

Post by Richard Wissler » 06 Jul 2007, 15:35

Hello Sergey;

Thank you very much for your quick reply. Works perfectly.

Richard

Post Reply