Page 1 of 1

How to delete a Layer

Posted: 24 Jun 2012, 13:06
by aby
Hi,

Is it possible to delete a layer?

I'm trying to remove a layer like the following with no success.

DXFConverter->DeleteEntity(Layer,true);

Re: How to delete a Layer

Posted: 25 Jun 2012, 11:11
by support
Hello aby.
A layer can be removed like: DXFConverter->Sections[csLayers]->DeleteEntity(Layer, true). Please note, a layer must be empty to avoid errors further. Also the layer "0" can be not removed.

Alexander.

Re: How to delete a Layer

Posted: 26 Jun 2012, 12:55
by aby
Hi,

Thanks for your fast reply.

I've one more issue. After deleting a layer, I could no more add a new Layer.

Before deleting I had 41 Layers, after deleting there is only 7 layers left in my test.

When I examine the code with debugger, FindEntByName in DXFCONV.file vindex's value is 39.

The issue is comming FSortEntList;

It seems coincedently there was a same layer name before deleting.

How can I remove the layername from FSortEntList?

I had examined your code releating to delete a Layer

There is no DeleteEntity method pertaning to TsgDxfTable class.
It is calling TsgDXFGroup's DeleteEntity method.
It seems DeleteEntity must have been overrided for TsgDxfTable class.
Remove the layername from FSortEntList in this method and then call TsgDxfTables DeleteClass method.

Any remedies.

Thanks

Aby



function TsgDXFTable.FindEntByName(const AName: string): TsgDXFEntity;
var
vIndex: Integer;
vName: string;
begin
Result := nil;
if FSortEntList <> nil then
begin
vIndex := FSortEntList.IndexOf(AName);

Re: How to delete a Layer

Posted: 28 Jun 2012, 15:22
by support
Hello Aby.
Deleting a layer(s) doesn't prevent creating a new one, even with a same name. Please try the following code to create a new layer:

Code: Select all

  TsgDXFLayer* layer = new TsgDXFLayer();
  layer->Name = "layer_name";
  Img->Converter->Sections[csLayers]->AddEntity(layer);
FSortEntList is the list of different objects that filled automatically. It's marked with private modifier that makes it not recommended for using. A new layer must be created even if FSortEntList contains an old one with a same name.
Is any error appears on unsuccessful creating attempt?

Alexander.

Re: How to delete a Layer

Posted: 28 Jun 2012, 16:07
by aby
Dear Alexander,

I am using LayerByName function to add a new Layer.

The issue is coming from LayerByName function.

LayerByName is calling FindEntByName which is returning a deleted object index.

I'm calling LayerByName intensivly in my program.

If I use your suggesting adding a Layer method, Does calling LayerByName function would return the proper layer?

Thanks.

Aby

This is taken from CADImport VCL help.

TsgDXFConverter.LayerByName

Returns layer with the name specified in AName.

function LayerByName(const AName: string): TsgDXFLayer;

Description

Returns layer with the name specified in AName. If layer does not exist LayerByName creates a new TsgDXFLayer class object.

Re: How to delete a Layer

Posted: 28 Jun 2012, 17:55
by support
Hello Aby.
Creating a new layer using the provided code snippet will allow to receive correct result from LayerByName function further call. The problem can occur if only create a new layer with the same name as a member of Converter->Sections[csLayers] already has.

Alexander.