Page 1 of 1

Sorting entities

Posted: 28 Aug 2018, 10:05
by Timo
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

Re: Sorting entities

Posted: 28 Aug 2018, 23:15
by support
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

Re: Sorting entities

Posted: 30 Aug 2018, 10:20
by Timo
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

Re: Sorting entities

Posted: 17 Sep 2018, 22:00
by support
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