Cant create a hatch as first entity , BUG?
Moderators: SDS, support, admin
Cant create a hatch as first entity , BUG?
I have been trying to create several entities in loop while exporting a vector drawing to DXF. The entities depend on actual contents of the onscreen drawing in a Delphi application.
Sometimes the first entity required to be created in DXF file (and sometime the only entity required) is a HATCH. In this case the exported file seems to be corrupt and while trying to open it in AutoCAD I get the following error message:
"The following error was encountered while reading
in HATCH starting at line 340:
Error: expected group code 91
Invalid or incomplete DXF input -- drawing discarded."
The simplimfied Delphi code being used for above is as below:
Please review the above code and tell me if I am doing something wrong or what.
Also sometime I encounter a delphi error message for invalid pointer operation while freeing the points (it can be seen through above code also. Maybe I am doing something in wrong manner. Please help.
thanking you in anticipation
SK Arora
Sometimes the first entity required to be created in DXF file (and sometime the only entity required) is a HATCH. In this case the exported file seems to be corrupt and while trying to open it in AutoCAD I get the following error message:
"The following error was encountered while reading
in HATCH starting at line 340:
Error: expected group code 91
Invalid or incomplete DXF input -- drawing discarded."
The simplimfied Delphi code being used for above is as below:
Code: Select all
<b>procedure</b> TForm1.FormCreate(Sender: TObject);
<b>var</b>
e: TsgDXFExport;
<b>begin</b>
e := TsgDXFExport.create;
<b>try</b>
DrawSubbasins(e);
<b>finally</b>
e.free ;
<b>end</b>;
<b>end</b>;
<b>procedure</b> TForm1.DrawSubbasins(E:TsgDXFExport);
<b>var</b>
Data: TdxfExportData;
vLayer: TsgExpDXFLayer;
Pt: PDXFPoint;
<b>procedure</b> FreeDataPoints;
<b>var</b>
J, K: Integer;
<b>begin
for</b> K := 0 <b>to</b> Data.Points.Count - 1 <b>do
begin
for</b> J := 0 <b>to</b> TList(Data.Points[K]).Count - 1 <b>do</b>
Dispose(TList(Data.Points[K]).Items[J]);
TList(Data.Points[K]).Free;
<b>end</b>;
<b>end</b>;
<b>begin</b>
vLayer := TsgExpDXFLayer.Create('StormNET Subbasins Fill');
e.CurrentLayer := vLayer;
Data.Color := ColorToDXF(clteal);
Data.Count := 4;
Data.Points := TList.Create;
Data.Points.Add(TList.Create);
<b>try</b>
New(Pt);
Pt^.X := 1000;
Pt^.Y := 1000;
Pt^.Z := 0;
TList(Data.Points[0]).Add(Pt);
Pt^.X := 1100;
Pt^.Y := 1000;
Pt^.Z := 0;
TList(Data.Points[0]).Add(Pt);
Pt^.X := 1100;
Pt^.Y := 2000;
Pt^.Z := 0;
TList(Data.Points[0]).Add(Pt);
Pt^.X := 1500;
Pt^.Y := 1500;
Pt^.Z := 0;
TList(Data.Points[0]).Add(Pt);
e.CurrentLayer := vLayer;
e.AddHatch(Data);
e.savetofile('C:\sampleHatch.dxf');
<b>finally</b>
FreeDataPoints;
Data.Points.Free;
<b>end</b>;
<b>end</b>;
Also sometime I encounter a delphi error message for invalid pointer operation while freeing the points (it can be seen through above code also. Maybe I am doing something in wrong manner. Please help.
thanking you in anticipation
SK Arora
Hello,
Important: current version (v.5.2.5) of DXFExportVCL (http://www.cadsofttools.com/download/dxfexportvcl.zip) supports double precision. It is necessary to use <b>PexpPoint</b> instead of <b>PDXFPoint</b>.
The following code works:
Sergey.
please post questions to the forum or write to support@cadsofttools.com
Important: current version (v.5.2.5) of DXFExportVCL (http://www.cadsofttools.com/download/dxfexportvcl.zip) supports double precision. It is necessary to use <b>PexpPoint</b> instead of <b>PDXFPoint</b>.
The following code works:
Code: Select all
<b>procedure</b> TForm1.Button3Click(Sender: TObject);
<b>procedure</b> DrawSubbasins(AExport: TsgDXFExport);
<b>var</b>
Data: TdxfExportData;
vLayer: TsgExpDXFLayer;
Pt: PexpPoint;
vList: TList;
<b>procedure</b> FreeDataPoints;
<b>var</b>
J, K: Integer;
vList: TList;
<b>begin
for</b> K := 0 <b>to</b> Data.Points.Count - 1 <b>do
begin</b>
vList := TList(Data.Points[K]);
Data.Points[K] := <b>nil</b>;
<b>for</b> J := vList.Count - 1 <b>downto</b> 0 <b>do</b>
Dispose(vList[J]);
vList.Free;
<b>end</b>;
<b>end</b>;
<b>begin</b>
vLayer := TsgExpDXFLayer.Create('StormNET Subbasins Fill');
AExport.CurrentLayer := vLayer;
Data.Color := ColorToDXF(clteal);
Data.Count := 4;
Data.Scale := cnstFPointSingle;
Data.Points := TList.Create;
vList := TList.Create;
Data.Points.Add(vList);
<b>try</b>
New(Pt);
Pt^.X := 1000;
Pt^.Y := 1000;
Pt^.Z := 0;
vList.Add(Pt);
New(Pt);
Pt^.X := 1100;
Pt^.Y := 1000;
Pt^.Z := 0;
vList.Add(Pt);
New(Pt);
Pt^.X := 1100;
Pt^.Y := 2000;
Pt^.Z := 0;
vList.Add(Pt);
New(Pt);
Pt^.X := 1500;
Pt^.Y := 1500;
Pt^.Z := 0;
vList.Add(Pt);
AExport.CurrentLayer := vLayer;
AExport.AddHatch(Data);
AExport.SaveToFile('C:\sampleHatch.dxf');
<b>finally</b>
FreeDataPoints;
Data.Points.Free;
<b>end</b>;
<b>end</b>;
<b>var</b>
vExport: TsgDXFExport;
<b>begin</b>
vExport := TsgDXFExport.Create;
<b>try</b>
DrawSubbasins(vExport);
<b>finally</b>
vExport.Free;
<b>end</b>;
<b>end</b>;
please post questions to the forum or write to support@cadsofttools.com