DXFExportVCL : how to export "multi Layers" DXF ?
Moderators: SDS, support, admin
DXFExportVCL : how to export "multi Layers" DXF ?
Hi all,
I'm trying to export some data in a "multi layers" DXF file.
This is my code :
<hr noshade size="1">
DXF := TsgDXFExport.Create;
DXF.AutoCADVer := R2000;
DXF.Millimetres := true;
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 1');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 2');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.EndDraw;
DXF.SaveToFile(SomeFile);
DXF.Destroy;
<hr noshade size="1">
The final file contains 3 layers "0" / "Sample 1" / "Sample 2", but the 2 Polyline objects are both in the "Sample 2" layer ...
Any idea ?
Thanks in advance.
Bye.
I'm trying to export some data in a "multi layers" DXF file.
This is my code :
<hr noshade size="1">
DXF := TsgDXFExport.Create;
DXF.AutoCADVer := R2000;
DXF.Millimetres := true;
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 1');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 2');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.EndDraw;
DXF.SaveToFile(SomeFile);
DXF.Destroy;
<hr noshade size="1">
The final file contains 3 layers "0" / "Sample 1" / "Sample 2", but the 2 Polyline objects are both in the "Sample 2" layer ...
Any idea ?
Thanks in advance.
Bye.
Hello!
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by Vilo</i>
<br />Hi all,
I'm trying to export some data in a "multi layers" DXF file.
This is my code :
<hr noshade size="1">
DXF := TsgDXFExport.Create;
DXF.AutoCADVer := R2000;
DXF.Millimetres := true;
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 1');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 2');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.EndDraw;
DXF.SaveToFile(SomeFile);
DXF.Destroy;
<hr noshade size="1">
The final file contains 3 layers "0" / "Sample 1" / "Sample 2", but the 2 Polyline objects are both in the "Sample 2" layer ...
Any idea ?
Thanks in advance.
Bye.
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Your actions provoke drawing on the inner (internal) canvas of the exporter. This is exactly immitation of metafile. That is why layers do not work.
Layers work for the direct export only. Please find respective example in the demo:
procedure TfmDXFExporter.btnFormShapesClick(Sender: TObject);
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by Vilo</i>
<br />Hi all,
I'm trying to export some data in a "multi layers" DXF file.
This is my code :
<hr noshade size="1">
DXF := TsgDXFExport.Create;
DXF.AutoCADVer := R2000;
DXF.Millimetres := true;
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 1');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 2');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.EndDraw;
DXF.SaveToFile(SomeFile);
DXF.Destroy;
<hr noshade size="1">
The final file contains 3 layers "0" / "Sample 1" / "Sample 2", but the 2 Polyline objects are both in the "Sample 2" layer ...
Any idea ?
Thanks in advance.
Bye.
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Your actions provoke drawing on the inner (internal) canvas of the exporter. This is exactly immitation of metafile. That is why layers do not work.
Layers work for the direct export only. Please find respective example in the demo:
procedure TfmDXFExporter.btnFormShapesClick(Sender: TObject);
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
Re: DXFExportVCL : how to export
In order to reuse a big piece of code, I want to export dxf via metafile and I'd like to useDXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 1');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 2');
DXF.Canvas.Polyline(SomePoints, gmPixels);
exactly this quoted wrong method of exporting dxf with several layers. Is it supported in new versions of DXFExport? Or could you suggest workarounds that allow to export layers with TsgDXFExport without switching to "direct" export?
Re: DXFExportVCL : how to export
If someone wonder, my current solution is to draw every layer on a separate TMetafile and then to load all metafiles in TsgDXFExport changing CurrentLayer every time before loading. Works well since LoadFromMetafile() doesn't erase previous changes in TsgDXFExport as I suspected earlier (at least, it seems so)Alsk wrote:...workarounds that allow to export layers with TsgDXFExport without switching to "direct" export?
Re: DXFExportVCL : how to export
Hello.
The method
Alexander.
The method
is wrong and it won't be supported in any latest versions. Correct method is export to dxf using separate metafile for each layer, like it's shown in our demo "DXFExporter".DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 1');
DXF.Canvas.Polyline(SomePoints, gmPixels);
DXF.CurrentLayer := TsgExpDXFLayer.Create('Sample 2');
DXF.Canvas.Polyline(SomePoints, gmPixels);
Alexander.
Re: DXFExportVCL : how to export
Well, since this wrong method is the most obvious one that a new user who don't read manuals will start with, I can't think of reasons why you don't implement it. Judging by your source code, it should be easy to create a separate metafile for every layer inside TsgDXFExport itself and to return appropriate TMetafileCanvas object from GetCanvas method for Canvas property considering value of CurrentLayer.
Re: DXFExportVCL : how to export
Hello.
In the demo DXFExporter there is a method that realizes correct export to DXF layers via metafiles:
Why don't use it?
Alexander.
In the demo DXFExporter there is a method that realizes correct export to DXF layers via metafiles:
Code: Select all
procedure TfmDXFExporter.btnEmfs2DXFClick(Sender: TObject);
var
vDXF: TsgDXFExport;
vLayer: TsgExpDXFLayer;
I: Integer;
begin
OpenPictureDialog.Options := OpenPictureDialog.Options + [ofAllowMultiSelect];
if not OpenPictureDialog.Execute then Exit;
vDXF := TsgDXFExport.Create;
try
SetDXFParams(vDXF);
for I := 0 to OpenPictureDialog.Files.Count - 1 do
begin
vLayer := TsgExpDXFLayer.Create(ChangeFileExt(ExtractFileName(OpenPictureDialog.Files.Strings[I]), ''));//, IntToStr(I));
vDXF.CurrentLayer := vLayer;
vDXF.LoadFromFile(OpenPictureDialog.Files.Strings[I]);
end;
vDXF.SaveToFile(ExtractFilePath(OpenPictureDialog.FileName)+'WMFs-LAYERS.dxf');
finally
vDXF.Free;
end;
end;
This task can be fulfiled by using such code:Alsk wrote:Judging by your source code, it should be easy to create a separate metafile for every layer inside TsgDXFExport itself and to return appropriate TMetafileCanvas object from GetCanvas method for Canvas property considering value of CurrentLayer.
Code: Select all
procedure TfmDXFExporter.btnPaintToClick(Sender: TObject);
var
E: TsgDXFExport;
begin
if not SaveDialog.Execute then Exit;
E := TsgDXFExport.Create;
DXFExport.OffsetY := Height; // Set OffsetY = height of the drawing
// also you can use OffseX - OffsetY and OffsetX are for with metafiles only
try
PaintTo(E.Canvas.Handle, 0, 0);
E.EndDraw;
E.SaveToFile(SaveDialog.FileName);
finally
E.Free;
end;
end;
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: DXFExportVCL : how to export
It seems that there is a misapprehension here. I use it already, and that works fine, thanks. Just would like to use it easier from the very beginning, because it is implementable.
Consider your modified source where all the details of work with several metafiles are incapsulated
supposing that FCanvas[] and FTmp[] are some sort of maps indexed with TsgExpDXFLayer objects
Consider your modified source where all the details of work with several metafiles are incapsulated
Code: Select all
function TsgDXFExport.GetCanvas: TCanvas;
begin
if FCanvas[CurrentLayer] = nil then
begin
FTmp[CurrentLayer] := TMetafile.Create;
FCanvas[CurrentLayer] := TMetafileCanvas.Create(FTmp[CurrentLayer], 0);
end;
Result := FCanvas[CurrentLayer];
end;
Re: DXFExportVCL : how to export
Hello.
Thank you for the code sample. It will be considered by our development sector.
Alexander.
Thank you for the code sample. It will be considered by our development sector.
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support