How to convert two metafile to one dxf with two layers
Moderators: SDS, support, admin
-
- Posts: 4
- Joined: 23 Jun 2022, 17:20
How to convert two metafile to one dxf with two layers
Hi,
I need to create a DXF file with two layers, then load two metafile and draw it one for layer.
How can i do?
I need to create a DXF file with two layers, then load two metafile and draw it one for layer.
How can i do?
Re: How to convert two metafile to one dxf with two layers
Hi, you should create a drawing, add layers and IMAGEENT entities to the drawing, then set the entities to the corresponding layers:pierpaolo.degrandis wrote: ↑24 Jun 2022, 17:44Hi,
I need to create a DXF file with two layers, then load two metafile and draw it one for layer.
How can i do?
Code: Select all
function AddImageEnt(ACADImage: TsgCADImage; const AFileName: string;
APosition: TFPoint; const ALayerName: string): TsgDXFImageEnt;
var
vImageDef: TsgDXFImageDef;
vImageDefName: string;
begin
Result := TsgDXFImageEnt.Create;
vImageDefName := ChangeFileExt(ExtractFileName(AFileName), '');
vImageDef := TsgDXFImageDef(ACADImage.Converter.Sections[csImageDefs].FindEntByName(vImageDefName));
if not Assigned(vImageDef) then
begin
vImageDef := TsgDXFImageDef.Create;
vImageDef.Name := vImageDefName;
vImageDef.FileName := AFileName;
ACADImage.Converter.Sections[csImageDefs].AddEntity(vImageDef);
ACADImage.Converter.Loads(vImageDef);
end;
Result.ImageDef := vImageDef;
Result.Point := APosition;
Result.Layer := ACADImage.Converter.LayerByName(ALayerName);
ACADImage.CurrentLayout.AddEntity(Result);
ACADImage.Converter.Loads(Result);
end;
Code: Select all
...
var
vImageEnt: TsgDXFImageEnt;
begin
vImageEnt := AddImageEnt(FImg, 'd:\New1.emf', MakeFPoint(0, 0, 0), 'my_layer1');
AddImageEnt(FImg, 'd:\New2.emf', MakeFPoint(vImageEnt.Width, 0, 0), 'my_layer2');
FImg.GetExtents;
btnFitToScreenClick(nil);
end;
Catherine.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 4
- Joined: 23 Jun 2022, 17:20
Re: How to convert two metafile to one dxf with two layers
Hi Catherine,
thanks for your reply.
I create this procedure to create a DXF file from two metafiles on two different layers:
but...
I have this problem:
If I delete the metafiles then the DXF will be empty.
It seems that metafiles are linked in DXF not realy imported.
What I wrong?
thanks for your reply.
I create this procedure to create a DXF file from two metafiles on two different layers:
Code: Select all
class procedure TImageConvertion.AddMetafileToCADImage(ACADFile: TsgCADImage; AFileName: string; AWidth: Integer; ALayerName: string);
var
vImageDef: TsgDXFImageDef;
DXFImageEnt: TsgDXFImageEnt;
vLayout: TsgDXFLayout;
begin
vImageDef := TsgDXFImageDef.create;
vImageDef.FileName := AFileName;
ACADFile.Converter.Loads(vImageDef);
if vImageDef.Picture.Graphic <> nil then
begin
ACADFile.Converter.Sections[csImageDefs].AddEntity(vImageDef);
DXFImageEnt := TsgDXFImageEnt.create;
DXFImageEnt.ImageDef := vImageDef;
DXFImageEnt.Point := MakeFPoint(0, 0, 0);
DXFImageEnt.UVector := cnstXOrtAxis;
DXFImageEnt.VVector := cnstYOrtAxis;
DXFImageEnt.Size := DXFImageEnt.ImageDef.Size;
DXFImageEnt.Width := AWidth;
if ALayerName <> '' then
DXFImageEnt.Layer := ACADFile.Converter.LayerByName(ALayerName);
vLayout := ACADFile.Converter.Layouts[0];
if vLayout <> nil then
begin
if Assigned(ACADFile.Converter.OnCreate) then
ACADFile.Converter.OnCreate(DXFImageEnt);
ACADFile.Converter.Loads(DXFImageEnt);
vLayout.AddEntity(DXFImageEnt);
end;
end;
end;
class procedure TImageConvertion.MetafileToDxfFile(ExportFilename: string; ImportFilename1, ImportFilename2: string)overload;
var
vDimStyle: TsgDXFDimensionStyle;
FCADFile1: TsgCADImage;
FDXFLayer: TsgDXFLayer;
vExp: TsgCADExport;
ext: string;
begin
FCADFile1 := TsgCADImage.create;
FCADFile1.Converter.InitializeSectionsBegin;
FCADFile1.Converter.InitializeSectionsEnd;
// vDimStyle := TsgDXFDimensionStyle(FCADFile1.Converter.DimensionStyleByName(FCADFile1.Converter.HeadVarStruct.DimStyle));
// vDimStyle.DIMBLK1T := datOpen;
// FCADFile1.Converter.Loads(vDimStyle);
AddMetafileToCADImage(FCADFile1, ImportFilename1, 5000, '');
FCADFile1.GetExtents;
AddMetafileToCADImage(FCADFile1, ImportFilename2, 5000, 'graphics');
ext := LowerCase(ExtractFileExt(ExportFilename));
if (ext = '.dxf') or (ext = '.dwg') then
begin
if ext = '.dxf' then
vExp := TsgCADtoDXF.create(FCADFile1)
else
vExp := TsgCADtoDWG.create(FCADFile1);
vExp.SaveToFile(ExportFilename);
vExp.Free;
end;
FCADFile1.Free;
end;
but...
I have this problem:
If I delete the metafiles then the DXF will be empty.
It seems that metafiles are linked in DXF not realy imported.
What I wrong?
Re: How to convert two metafile to one dxf with two layers
Hello,
Please use the code example below:
type
TsgDXFExportAccess = class(TsgDXFExport);
procedure TfmDXFExporter.btnEmf2dwgClick(Sender: TObject);
var
vExport: TsgDXFExport;
I: Integer;
vCADImage: TsgVectorImage;
vLayers: TStringList;
vMetafile: TMetafile;
vImageInInClip: Boolean;
vBox: TFRect;
begin
OpenPictureDialog.Options := OpenPictureDialog.Options +
[ofAllowMultiSelect];
if not OpenPictureDialog.Execute then Exit;
if cbUseOneFile.Checked then
begin
vCADImage := TsgVectorImage.Create;
vCADImage.Converter.InitializeSectionsBegin;
vCADImage.Converter.InitializeSectionsEnd;
vCADImage.CurrentLayout := vCADImage.Layouts[0];
vExport := TsgDXFExport.Create;
try
TsgDXFExportAccess(vExport).SetCADImage(vCADImage);
SetDXFParams(vExport);
vLayers := TStringList.Create;
try
vLayers.OwnsObjects := True;
vBox := MakeFRectByPoints(cnstFPointZero, cnstFPointZero);
for I := 0 to OpenPictureDialog.Files.Count - 1 do
begin
vMetafile := TMetafile.Create;
vMetafile.LoadFromFile(OpenPictureDialog.Files.Strings);
ExpandFRect(vBox, MakeFPointFrom2D(GetMetafileSize(vMetafile)));
vLayers.AddObject(ExtractFileName(OpenPictureDialog.Files.Strings),
vMetafile);
end;
ConvertToCad(nil, vLayers, vCADImage, vBox, nil, '', nil, nil,
vImageInInClip);
finally
vLayers.Free;
end;
vExport.SaveToFile(ChangeFileExt(OpenPictureDialog.Files.Strings[0],
'.dwg'));
finally
vExport.Free;
end;
end
else
for I := 0 to OpenPictureDialog.Files.Count - 1 do
begin
vExport := TsgDXFExport.Create;
try
SetDXFParams(vExport);
vExport.LoadFromFile(OpenPictureDialog.Files.Strings);
vExport.SaveToFile(ChangeFileExt(OpenPictureDialog.Files.Strings,
'.dwg'));
finally
vExport.Free;
end;
end;
end;
Kind regards,
Suraya
Please use the code example below:
type
TsgDXFExportAccess = class(TsgDXFExport);
procedure TfmDXFExporter.btnEmf2dwgClick(Sender: TObject);
var
vExport: TsgDXFExport;
I: Integer;
vCADImage: TsgVectorImage;
vLayers: TStringList;
vMetafile: TMetafile;
vImageInInClip: Boolean;
vBox: TFRect;
begin
OpenPictureDialog.Options := OpenPictureDialog.Options +
[ofAllowMultiSelect];
if not OpenPictureDialog.Execute then Exit;
if cbUseOneFile.Checked then
begin
vCADImage := TsgVectorImage.Create;
vCADImage.Converter.InitializeSectionsBegin;
vCADImage.Converter.InitializeSectionsEnd;
vCADImage.CurrentLayout := vCADImage.Layouts[0];
vExport := TsgDXFExport.Create;
try
TsgDXFExportAccess(vExport).SetCADImage(vCADImage);
SetDXFParams(vExport);
vLayers := TStringList.Create;
try
vLayers.OwnsObjects := True;
vBox := MakeFRectByPoints(cnstFPointZero, cnstFPointZero);
for I := 0 to OpenPictureDialog.Files.Count - 1 do
begin
vMetafile := TMetafile.Create;
vMetafile.LoadFromFile(OpenPictureDialog.Files.Strings);
ExpandFRect(vBox, MakeFPointFrom2D(GetMetafileSize(vMetafile)));
vLayers.AddObject(ExtractFileName(OpenPictureDialog.Files.Strings),
vMetafile);
end;
ConvertToCad(nil, vLayers, vCADImage, vBox, nil, '', nil, nil,
vImageInInClip);
finally
vLayers.Free;
end;
vExport.SaveToFile(ChangeFileExt(OpenPictureDialog.Files.Strings[0],
'.dwg'));
finally
vExport.Free;
end;
end
else
for I := 0 to OpenPictureDialog.Files.Count - 1 do
begin
vExport := TsgDXFExport.Create;
try
SetDXFParams(vExport);
vExport.LoadFromFile(OpenPictureDialog.Files.Strings);
vExport.SaveToFile(ChangeFileExt(OpenPictureDialog.Files.Strings,
'.dwg'));
finally
vExport.Free;
end;
end;
end;
Kind regards,
Suraya
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 4
- Joined: 23 Jun 2022, 17:20
Re: How to convert two metafile to one dxf with two layers
Hi Suraya,
starting from DXFExporter demo example, I've replaced TfmDXFExporter.btnEmf2dwgClick method with your one.
I have some compilation errors:
Cannot find:
TsgDXFExportAccess(vExport).SetCADImage(vCADImage);
Cannot find:
ConvertToCad(nil, vLayers, vCADImage, vBox, nil, '', nil, nil, vImageInInClip);
Can you help me?
(I suppose your snippet start from an older version than 15)
starting from DXFExporter demo example, I've replaced TfmDXFExporter.btnEmf2dwgClick method with your one.
I have some compilation errors:
Cannot find:
TsgDXFExportAccess(vExport).SetCADImage(vCADImage);
Cannot find:
ConvertToCad(nil, vLayers, vCADImage, vBox, nil, '', nil, nil, vImageInInClip);
Can you help me?
(I suppose your snippet start from an older version than 15)
Re: How to convert two metafile to one dxf with two layers
Hello,
Thank you for the information.
It was forwarded to our department of software developers.
We will contact you by e-mail to get more details.
Kind regards,
Suraya Mamedova
Thank you for the information.
It was forwarded to our department of software developers.
We will contact you by e-mail to get more details.
Kind regards,
Suraya Mamedova
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 4
- Joined: 23 Jun 2022, 17:20
Re: How to convert two metafile to one dxf with two layers
Hi Suraya
thank you for your support.
I finally solved:
I've add a method to class TsgDXFExportDirect to export a list of metafile in more layers:
I call this method like this:
I've inverted the order of metafile (and layers) because I need the first layers to be in front of the second one (as you noted me).
Many thanks.
thank you for your support.
I finally solved:
I've add a method to class TsgDXFExportDirect to export a list of metafile in more layers:
Code: Select all
procedure TsgDXFExportDirect.LoadLayersFromMetafiles(MetafileList: TStringList);
var
vMetafileLoader: TsgConvertMetafileToCad;
vBox: TFRect;
LastMetafile: TMetafile;
begin
try
FreeAndNil(FCADImage);
except
{$IFDEF _FIXINSIGHT_} on E: Exception do
EmptyExceptionHandler(E); {$ENDIF}
end;
FCADImage := TsgVectorImage.Create;
try
LastMetafile := TMetafile(MetafileList.Objects[MetafileList.Count - 1]);
FCADImage.Converter.InitializeSectionsBegin;
FCADImage.Converter.InitializeSectionsEnd;
FCADImage.CurrentLayout := FCADImage.Layouts[0];
if IsBadRect(FOwnerBox) then
vBox := MakeFRectByPoints(cnstFPointZero, MakeFPointFrom2D(GetMetafileSize(LastMetafile)))
else
vBox := FOwnerBox;
vMetafileLoader := TsgConvertMetafileToCad.Create(FCADImage, nil, vBox, '', FExtData);
try
vMetafileLoader.AlternateBlack := AlternateBlack;
vMetafileLoader.Use01MM := Use01MM;
vMetafileLoader.Scale := Scale;
vMetafileLoader.UnitSize := UnitSize;
vMetafileLoader.OffsetX := Offset.X;
vMetafileLoader.OffsetY := Offset.Y;
vMetafileLoader.LineWeightScale := FLineWeightScale;
vMetafileLoader.Convert(MetafileList, nil);
finally
vMetafileLoader.Free;
end;
except
FreeAndNil(FCADImage);
end;
end;
Code: Select all
class procedure TImageConvertion.MetafileToDxfFile(ExportFilename: string; Metafile1, Metafile2: TMetafile)overload;
var
vExport: TsgDXFExport;
AList: TStringList;
Begin
vExport := TsgDXFExport.create;
try
vExport.AlternateBlack := false;
vExport.Use01MM := false;
vExport.Version := acR2004;
vExport.Millimetres := True;
vExport.Scale := 0.01;
AList := TStringList.Create;
AList.AddObject('Second', Metafile2);
AList.AddObject('', Metafile1);
vExport.LoadLayersFromMetafiles(AList);
vExport.SaveToFile(ExportFilename);
finally
vExport.Free;
end;
end;
Many thanks.
Re: How to convert two metafile to one dxf with two layers
Hello,
You are welcome!
Feel free to contact us if any questions arise.
Kind regards,
Suraya Mamedova
You are welcome!
Feel free to contact us if any questions arise.
Kind regards,
Suraya Mamedova
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support