Entities of specific layer
Moderators: SDS, support, admin
Entities of specific layer
Describe me, pls, the way to iterate all entities of specific layer.
Thank you for your help.
Thank you for your help.
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:
Sergey.
please post questions to the forum or write to support@cadsofttools.com
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>;
please post questions to the forum or write to support@cadsofttools.com
Hello,
Here goes expanded code:
<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
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>;
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