Entities of specific layer

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

Moderators: SDS, support, admin

Post Reply
Diman
Posts: 2
Joined: 03 Apr 2006, 13:48

Entities of specific layer

Post by Diman » 03 Apr 2006, 13:52

Describe me, pls, the way to iterate all entities of specific layer.

Thank you for your help.

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

Post by support » 03 Apr 2006, 20:40

Hello Diman!

Here goes an example based on Demo Viewer from CADImportVCL (available on: http://www.cadsofttools.com/download/cadimportvcl.zip) package in ...\CADImportVCL\Delphi\Demos\Viewer\.. folder:

Code: Select all

<b>procedure</b> TForm1.IterateLayer1Click(Sender: TObject);
<b>var</b>
  I: Integer;
  vImg: TsgDXFImage;
<b>begin
  try</b>
    // sgPaintBox: TsgImage
    vImg := TsgDXFImage(sgPaintBox.Picture.Graphic);
  <b>except</b>
    // sgPaintBox.Picture.Graphic is not TsgDXFImage
    Exit;
  <b>end</b>;
  <b>for</b> I := 0 <b>to</b> vImg.Converter.Counts[csLayers] - 1 <b>do
  begin
    if</b> (vImg.Converter.Layers[I].Name = 'Layer1') <b>then</b>
      vImg.Converter.Layers[I].Frozen := False
    <b>else</b>
      vImg.Converter.Layers[I].Frozen := True;
  <b>end</b>;
// iterate:      vImg.CurrentLayout.Iterate(vImg.Converter, Proc);
// Proc - user defined procedure
  sgPaintBox.Invalidate;   // in Viewer demo allows to show "Layer1" only
<b>end</b>;
Sergey.

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

Diman
Posts: 2
Joined: 03 Apr 2006, 13:48

Post by Diman » 04 Apr 2006, 12:47

I've tested your examle.
After Layers.Frozen:=True procedure vImg.CurrentLayout.Iterate iterates ALL entities in ALL layers.
When I commented lines with frozing this procedure iterates ALL entities in ALL layers again.
What for frozing? And how can I iterate all entities of SPECIFIC layer?

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

Post by support » 04 Apr 2006, 17:07

Hello,

Here goes expanded code:

Code: Select all

  TForm1 = <b>class</b>(TForm)
    ...
  <b>private</b>
    ...
    FCADParams: TsgCADIterate;
  <b>public</b>
    ...
    <b>procedure</b> ReadLayerEntities(Entity: TsgDXFEntity);

<b>var</b>
  ...
  MyLayerName: <b>String</b>;

<b>procedure</b> TForm1.IterateLayer1Click(Sender: TObject);
<b>var</b>
  vImg: TsgDXFImage;
<b>begin</b>
  MyLayerName := 'Layer1';
  <b>try</b>
    // sgPaintBox: TsgImage
    vImg := TsgDXFImage(sgPaintBox.Picture.Graphic);
  <b>except</b>
    // sgPaintBox.Picture.Graphic is not TsgDXFImage
    Exit;
  <b>end</b>;
  vImg.CurrentLayout.Iterate(vImg.Converter, ReadLayerEntities);
<b>end</b>;

<b>procedure</b> TForm1.ReadLayerEntities(Entity: TsgDXFEntity);
<b>var</b>
  S: <b>String</b>;
  L: TsgDXFLayer;  
<b>begin</b>
  DoScale2D(FCADParams); // calculates 2d scale and rotation
  
  L := EntLayer(Entity, FCADParams.Insert);
  <b>if</b> L <> <b>nil then
    if</b> L.Name = MyLayerName <b>then
    begin</b>
      S := Entity.EntName;
     // example
     // for instance:
     //  ShowMessage(S); 
    <b>end</b>;
<b>end</b>;
<b>Important</b>:

Do not use Entity.Layer.Name because layer of entity depends on Blocks and Block references where this Entity can be used.

ReadLayerEntities - user defined <b>procedure</b>.

<b>function</b> EntLayer(E: TsgDXFEntity; Ins: TsgDXFInsert): TsgDXFLayer;
<b>Description</b>:
Returns the real layer of the entity independently of inserts. If this layer is off, the entity is off. For instance if layer of entity is "0" while Entity's Insert layers is "Layer1", the function returns "Layer1" this is similar to AutoCAD.

Sergey.

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

Post Reply