DWG to DXF conversion

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

DWG to DXF conversion

Post by Richard Wissler » 28 Mar 2006, 20:53

I am looking for the easiest way to read a DWG file using CAD Import VCL and write its contents to DXF using DXF Export VCL. Do I have to iterate through the entities?

Rest regards
Richard

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

Post by support » 29 Mar 2006, 14:57

Dear Mr. Richard Wissler,

Here goes an example of import-export through metafile without iterating entities. This example is created basing on Demo Viewer from ..\CADImportVCL\Delphi\Demos\Viewer\.. folder (<b>CADImportVCL</b> is available on: http://www.cadsofttools.com/download/cadimportvcl.zip).
<b>Note</b>: it is necessary to add to the project module <b>DXFExport</b> (<b>DXFExportVCL</b> is available on: http://www.cadsofttools.com/download/dxfexportvcl.zip)

Code: Select all

<b>procedure</b> TForm1.SaveToDXF(AFileName: <b>string</b>);
<b>var</b>
  E: TsgDXFExport;
  vMet: TMetafile;
  vGr: TGraphic;
  vOffX, vOffY, vUSize: TsgFloat;
<b>begin</b>
  vGr := sgPaintBox.Picture.Graphic;
  E := TsgDXFExport.Create;
  <b>try</b>
    E.IsParseWhite := True;// False
    <b>if not</b> ((vGr <b>is</b> TsgDXFImage) <b>or</b> (vGr <b>is</b> TMetafile)) <b>then
    begin</b>
      ShowMessage('Raster drawings can not be saved to DXF format');
      Exit;
    <b>end
    else
    begin
      if not</b> (vGr <b>is</b> TsgDXFImage) <b>then
      begin</b>
        E.Use01MM := False;
        E.Canvas.StretchDraw(Rect(0, 0, vGr.Width, vGr.Height), vGr);
        E.EndDraw;
      <b>end
      else
      begin</b>
        vMet := TsgDXFImage(vGr).ExportToMetafile(vOffX, vOffY, vUSize);
        DXFExport.OffsetX := vOffX;
        DXFExport.OffsetY := vOffY;
        E.UnitSize := vUSize;
        E.LoadFromMetafile(vMet);
        vMet.Free;
      <b>end</b>;
    <b>end</b>;
    E.SaveToFile(AFileName);
  <b>finally</b>
    E.Free;
  <b>end</b>;
<b>end</b>;
Current version of <b>DXFExportVCL</b> implements export to DXF through metafile only.
We plan to release direct export to DXF soon. The whole inner structure of CAD file will be saved.

Best regards,
Sergey Verbenko

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

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

Post by support » 29 Mar 2006, 16:37

Hello all!!!

It is very important to note that when implementing the import-export through metafile the inner stucture of CAD file changes.
Finally the same picture is received when viewing source and destination files. But block and layers are lost and some copmplicated entites are converted to lines.

Sergey.

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

Post Reply