Export DXF DWG

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

Moderators: admin, support, SDS

Post Reply
forest
Posts: 3
Joined: 06 Mar 2018, 16:12

Export DXF DWG

Post by forest » 06 Mar 2018, 16:24

Hello

I'm using CAD VCL 11.0 and I'm doing DXF and DWG export with TsgCADtoDXF and TsgCADtoDWG.
Most of the time the file can not be opened by Autocad.

I tried everything without success, thank you for your help.

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

Re: Export DXF DWG

Post by support » 06 Mar 2018, 17:07

Hello,

Do you create DXF and DWG files from scratch or resave the existing files? Please post your code, so that we could find what is going wrong.


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

forest
Posts: 3
Joined: 06 Mar 2018, 16:12

Re: Export DXF DWG

Post by forest » 07 Mar 2018, 11:37

Hello
I delete the file before rewriting it
Here is the code

Code: Select all

procedure TForm_FaceAvant.SaveToDXF;
var
  AFileName         : string;

  vMC               : TMetafileCanvas;
  vM                : TMetafile;
  Nom_wmf           : string;

  vExport: TsgCADExport;
begin
  Try
    SaveDialogDXF.Filter := TXt_filtre_dwg+'|'+TXt_filtre_dxf+'|'+TXt_filtre_wmf;
    if not SaveDialogDXF.Execute then Exit;

    if (pos('.dxf', SaveDialogDXF.FileName) = 0) and (pos('.wmf', SaveDialogDXF.FileName) = 0) and (pos('.dwg', SaveDialogDXF.FileName) = 0)then
    begin
      case SaveDialogDXF.FilterIndex of
        1: AFileName := SaveDialogDXF.FileName + '.dwg';
        2: AFileName := SaveDialogDXF.FileName + '.dxf';
        3: AFileName := SaveDialogDXF.FileName + '.wmf';
      end;
    end
    else AFileName := SaveDialogDXF.FileName;

    if FileExists(AFileName) then
    begin
      if Application.MessageBox(PChar(TXT_DXFDejaExistant), PChar(RSAttention), MB_OKCANCEL) = IDCANCEL then exit;
       DeleteFile(AFileName);
    end;

    if pos('.dxf', AFileName) > 0 then
    begin
      vExport := TsgCADtoDXF.Create(TsgCADImage(sgPaintBox.Picture.Graphic)); //direct export
      try
        vExport.SaveToFile(AFileName);
      Except
        vExport.Free
      end;
      vExport.Free;
    end else
    if pos('.dwg', AFileName) > 0 then
    begin
      vExport := TsgCADtoDWG.Create(TsgCADImage(sgPaintBox.Picture.Graphic)); //direct export
      try
        vExport.SaveToFile(AFileName);
      Except
        vExport.Free
      end;
      vExport.Free
    end else
    begin
      vM := TMetafile.Create;
      try
        vM.Width := FsgPaintBox.Width;
        vM.Height := FsgPaintBox.Height;
        vMC := TMetafileCanvas.Create(vM, 0);
        try
          vMC.StretchDraw(FsgPaintBox.ClientRect, FsgPaintBox.Picture.Graphic);
        Except
          vMC.Free;
        end;
          vMC.Free;
        vM.SaveToFile(AFilename);
      Except
        vM.Free;
      end;
      vM.Free;
    end;
  Finally
  End;

end;

forest
Posts: 3
Joined: 06 Mar 2018, 16:12

Re: Export DXF DWG

Post by forest » 09 Mar 2018, 12:14

Further information:
  - The DWG export generates a bug each time.
  - If there is TsgDXFDimension then the DXF export generates a bug each time.

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

Re: Export DXF DWG

Post by support » 12 Mar 2018, 22:17

Hello,

Thank you for the information.

Your code for direct export to DWG/DXF formats uses improper class (TsgCADExport). You should use TsgCADDirectExport derivatives - TsgCADtoDWG and TsgCADtoDXF, depending on the output file extension (.dwg or .dxf).

Code: Select all

uses
  ..., SysUtils, CADImage, CADtoDWG, CADtoDXF;

...

implementation

{$R *.dfm}

...

procedure SaveToDWG(ACADImage: TsgCADImage; AFileName: string);
var
  vCADtoDWG: TsgCADtoDWG;
begin
  if not Assigned(ACADImage) then Exit;
  vCADtoDWG := TsgCADtoDWG.Create(ACADImage);
  try
    vCADtoDWG.SaveToFile(AFileName);
  finally
    vCADtoDWG.Free;
  end;
end;

procedure SaveToDXF(ACADImage: TsgCADImage; AFileName: string);
var
  vCADtoDXF: TsgCADtoDXF;
begin
  if not Assigned(ACADImage) then Exit;
  vCADtoDXF := TsgCADtoDXF.Create(ACADImage);
  try
    vCADtoDXF.SaveToFile(AFileName);
  finally
    vCADtoDXF.Free;
  end;
end;

procedure TForm_FaceAvant.SaveToCADByFileFormat(AFileName: string);
var
  vFileExt: string;
begin
  vFileExt := AnsiLowerCase(ExtractFileExt(AFileName));
  if (vFileExt = '.dxf') then
    SaveToDXF(TsgCADImage(sgPaintBox.Picture.Graphic), AFileName);
  if (vFileExt = '.dwg') then
    SaveToDWG(TsgCADImage(sgPaintBox.Picture.Graphic), AFileName);
end;
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

FieldConsult
Posts: 54
Joined: 14 Mar 2015, 22:33

Re: Export DXF DWG

Post by FieldConsult » 03 Jun 2018, 20:47

This problem is coming form long time ago, I can see another user with the same problem.

I have tried both alternatives, loading an empty file and creating a new one in memory, in both cases the problem is the same.

I think what is needed is the publication of what entities is really capable of saving with CADExport?

Thaks!

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

Re: Export DXF DWG

Post by support » 04 Jun 2018, 18:02

Hello,

CADExport is the ancestor class of all export classes, you shouldn't use it for saving to DWG/DXF.

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply