AddScaledDXF question

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

Moderators: SDS, support, admin

Post Reply
gnl
Posts: 9
Joined: 05 Oct 2006, 23:40
Location: Greece

AddScaledDXF question

Post by gnl » 05 Oct 2006, 23:44

Dear Sergey,

I have managed to superimpose a second .dxf drawing over the original drawing by means of AddScaledDXF but I can not delete this superimposed drawing after I have done using it. I have tried with DeleteEntity but to no avail. Please help.

Regards,
George

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

Post by support » 06 Oct 2006, 10:46

Dear George,

Please use the following example. Note: we use here <b>AddScaledDXFEx</b> function instead of <b>AddScaledDXF</b>.

Code: Select all

<b>uses</b>
  ...
  DXFImage, DXFConv, SGImage, sgConsts;

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    ...
    Button1: TButton;
    Button2: TButton;
    sgImage1: TsgImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  <b>private</b>
    { Private declarations }
    Img, Img2: TsgDXFImage;
  <b>public</b>
    { Public declarations }
  <b>end</b>;

...
<b>procedure</b> TForm2.Button1Click(Sender: TObject);
<b>var</b>
  P: TFPoint;
<b>begin</b>
  sgImage1.LoadFromFile('c:\test.dxf');
  Img := TsgDXFImage(sgImage1.Picture.Graphic);
  sgImage1.Align := alClient;
  P := MakeFPoint(Img.Extents.Left, Img.Extents.Bottom, 0);
  Img2 := TsgDXFImage.Create;
  Img2.LoadFromFile('c:\xreftest.dxf');
  Img.AddScaledDXFEx(Img2,'xreftest.dxf',P,MakeFPoint(1,1,1),0.0);
<b>end</b>;

<b>procedure</b> TForm2.Button2Click(Sender: TObject);
<b>var</b>
  vIns: TsgDXFInsert;
  vBlock: TsgDXFBlock;

  <b>function</b> GetInsert(<b>const</b> AName: string): TsgDXFInsert;
  <b>var</b>
    I, J: Integer;
    vLayout: TsgDXFLayout;
    
    <b>function</b> IsInsert(<b>const</b> AEnt: TsgDXFEntity): Boolean;
    <b>var</b>
      vInsert: TsgDXFInsert <b>absolute</b> AEnt;
    <b>begin</b>
      Result := (vInsert.Block <> <b>nil</b>) <b>and</b> (vInsert.Block.Name = AName) 
    <b>end</b>;

  <b>begin</b>
    Result := <b>nil</b>;
    <b>for</b> I := Img.CurrentLayout.Count - 1 <b>downto</b> 0 <b>do
    begin
      if</b> IsInsert(Img.CurrentLayout.Entities[I]) <b>then
      begin</b>
        Result := TsgDXFInsert(Img.CurrentLayout.Entities[I]);
        Break;
      <b>end</b>;
    <b>end</b>;
    <b>if</b> Result <> <b>nil then</b> Exit;
    <b>for</b> I := Img.LayoutsCount - 1 <b>downto</b> 0 <b>do
    begin</b>
      vLayout := Img.Layouts[I];
      <b>if</b> vLayout = Img.CurrentLayout <b>then</b> Continue;
      <b>for</b> J := vLayout.Count - 1 <b>downto</b> 0 <b>do
      begin
        if</b> IsInsert(vLayout.Entities[I])<b>then
        begin</b>
          Result := TsgDXFInsert(vLayout.Entities[I]);
          Break;
        <b>end</b>;
      <b>end</b>;
      <b>if</b> Result <> <b>nil then</b> Break;
    <b>end</b>;
  <b>end</b>;

<b>begin
  if</b> Img = <b>nil then</b>
    Exit;

  vIns := GetInsert('xreftest.dxf');
  vBlock  := vIns.Block;
  vIns.Block := <b>nil</b>;
  Img.Converter.DeleteBlock(vBlock, True);  
<b>end</b>;

<b>end</b>.
Sergey.

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

gnl
Posts: 9
Joined: 05 Oct 2006, 23:40
Location: Greece

Post by gnl » 07 Oct 2006, 20:14

Really thanks Sergey !!

Post Reply