How to Explode a Block

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

Moderators: admin, support, SDS

Post Reply
FieldConsult
Posts: 53
Joined: 14 Mar 2015, 22:33

How to Explode a Block

Post by FieldConsult » 16 Mar 2015, 22:33

Hi:

Can you show a code for exploding blocks.

Thanks!

sanket
Posts: 2
Joined: 03 Dec 2018, 13:22

Re: How to Explode a Block

Post by sanket » 22 Jan 2019, 17:51

Hi,

Even I am having the same query. Can anyone please help ?

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

Re: How to Explode a Block

Post by support » 01 Feb 2019, 19:45

Hello,

Below you will find the requested sample code.

Code: Select all

interface

uses

..., CADImage, DXFConv, sgFunction, sgConsts;

...

implementation

{$R *.dfm}

procedure ExplodeInsert(ACADImage: TsgCADImage; AInsert: TsgDXFInsert);
var
  I, J: Integer;
  vBlockEnt: TsgDXFEntity;
  vDXFInsert: TsgDXFInsert;
  vDXFLine: TsgDXFLine;
  vDXFLWPolyline: TsgDXFPolyline;
  vDXFCircle: TsgDXFCircle;

  vMatrix: TFMatrix;
  vPoint, vScale, vExtrusion: TFPoint;
  vAngle: Double;
begin
  vMatrix := AInsert.GetMatrix;

  // Iterate through entities in the block
  for I := 0 to AInsert.Block.Count - 1 do
  begin
    vBlockEnt := AInsert.Block.Entities[I];
    case vBlockEnt.EntType of
        ceLine: // LINE entity
          begin
            // Create a copy of the entity which is inside the block
            vDXFLine := TsgDXFLine.Create;
            vDXFLine.AssignEntity(vBlockEnt);
            // Multiply coordinates of the created entity by the transformation matrix
            vDXFLine.Point := FPointXMat(vDXFLine.Point, vMatrix);
            vDXFLine.Point1 := FPointXMat(vDXFLine.Point1, vMatrix);
            ACADImage.Converter.Loads(vDXFLine);
            ACADImage.CurrentLayout.AddEntity(vDXFLine);
          end;
        ceLWPolyline: // LWPOLYLINE entity
          begin
            vDXFLWPolyline := TsgDXFLWPolyline.Create;
            vDXFLWPolyline.AssignEntity(vBlockEnt);
            for J := 0 to vDXFLWPolyline.Count - 1 do
              vDXFLWPolyline.Vertexes[J].Point := FPointXMat(vDXFLWPolyline.Vertexes[J].Point, vMatrix);
            ACADImage.Converter.Loads(vDXFLWPolyline);
            ACADImage.CurrentLayout.AddEntity(vDXFLWPolyline);
          end;
        ceCircle: // CIRCLE entity
          begin
            vDXFCircle := TsgDXFCircle.Create;
            vDXFCircle.AssignEntity(vBlockEnt);
            vDXFCircle.Point := FPointXMat(vDXFCircle.Point, vMatrix);
            vDXFCircle.Radius := DistanceFVector(AffineTransformPoint(MakeFPoint(0, vDXFCircle.Radius, 0), vMatrix));
            ACADImage.Converter.Loads(vDXFCircle);
            ACADImage.CurrentLayout.AddEntity(vDXFCircle);
          end;
        ceInsert: // nested INSERT entity
          begin
            //ExplodeInsert(ACADImage, vSrcEnt as TsgDXFInsert);
            vDXFInsert := TsgDXFInsert.Create;
            vDXFInsert.AssignEntity(vBlockEnt);
            ExtractMatrixParams(FMatXMat(TsgDXFInsert(vBlockEnt).GetMatrix, vMatrix), vPoint, vScale, vExtrusion, vAngle);
            vDXFInsert.Point := vPoint;
            vDXFInsert.Scale := vScale;
            vDXFInsert.Extrusion := vExtrusion;
            vDXFInsert.Angle := vAngle;
            ACADImage.Converter.Loads(vDXFInsert);
            ACADImage.CurrentLayout.AddEntity(vDXFInsert);
          end;
    end;
  end;
  // Delete the INSERT after exploding
  ACADImage.Converter.RemoveEntity(AInsert, True);
  // Recalculate the CAD image extents
  ACADImage.GetExtents();
end;
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply