Page 1 of 1

Export DXF DWG

Posted: 06 Mar 2018, 16:24
by forest
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.

Re: Export DXF DWG

Posted: 06 Mar 2018, 17:07
by support
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

Re: Export DXF DWG

Posted: 07 Mar 2018, 11:37
by forest
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;

Re: Export DXF DWG

Posted: 09 Mar 2018, 12:14
by forest
Further information:
  - The DWG export generates a bug each time.
  - If there is TsgDXFDimension then the DXF export generates a bug each time.

Re: Export DXF DWG

Posted: 12 Mar 2018, 22:17
by support
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

Re: Export DXF DWG

Posted: 03 Jun 2018, 20:47
by FieldConsult
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!

Re: Export DXF DWG

Posted: 04 Jun 2018, 18:02
by support
Hello,

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

Mikhail