Sorting entities

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

Moderators: support, SDS, admin

Post Reply
Timo
Posts: 8
Joined: 14 Oct 2009, 14:01

Sorting entities

Post by Timo » 28 Aug 2018, 10:05

Hi

I have some TsgCADCurvePolygon entities and TsgDXFinsert entities.
Sometimes CurvePolygon entities are drawn over DXFinserts and sometimes vice versa.
Can you give some example code for sorting entities? DXFInserts should be drawn over CurvePolygons which has solid fill.

This is correct:
Image

incorrect;
Image

-- Timo

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

Re: Sorting entities

Post by support » 28 Aug 2018, 23:15

Hello Timo,

The draw order depends on entity index in the Model space block (block with name '*MODEL_SPACE'). Entities are drawn in the following order: Entities[0], Entities[1], Entities[2], etc. that means the entity with a higher index value is drawn on top of the entity with a lower index value.

We may give you a sample code which moves entities of a certain type (e.g. inserts of a given block) to the top of the draw order, so that these entities will be drawn over other entities. If you need some other criteria for sorting, let us know.

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Timo
Posts: 8
Joined: 14 Oct 2009, 14:01

Re: Sorting entities

Post by Timo » 30 Aug 2018, 10:20

Hi,

All entities on layer "Koki_Grafiikka_Tausta" should drawn first as background (solid fill entites) and all other entities in their default drawing order.

-- Timo

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

Re: Sorting entities

Post by support » 17 Sep 2018, 22:00

Hello Timo,

Sorry for the delay in our reply.

Please try the following routine:

Code: Select all

procedure SendEntitiesToBack(ACADImage: TsgCADImage; ALayerName: string; EntType: TsgCADEntities);
var
  I, Count: Integer;
  vModelSpaceBlock: TsgDXFBlock;
  vDXFEntity: TsgDXFEntity;
begin
  I := 0;
  Count := 0;
  vModelSpaceBlock := ACADImage.Converter.BlockByName('*MODEL_SPACE');

  while I < vModelSpaceBlock.Count do
  begin
    vDXFEntity := vModelSpaceBlock.Entities[I];
    if ((vDXFEntity.EntType = EntType) and (vDXFEntity.Layer.Name = ALayerName)) then
    begin
      Inc(Count);
      vModelSpaceBlock.InsertEntity(Count - 1, vDXFEntity);
      vModelSpaceBlock.DeleteEntity(I + 1);
    end;
    Inc(I);
  end;
end;
To draw the solid fill entities which belong to the layer "Koki_Grafiikka_Tausta" at first, you should call the given routine as follows, then redraw the CAD image.

Code: Select all

SendEntitiesToBack(vCADImage, 'Koki_Grafiikka_Tausta', ceCurvePolygon);
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply