Skip to main content

Read block, attributes

uses DXF, DXFConv, sgConsts;

...

implementation

procedure TForm1.ReadBlockAttributesClick(Sender: TObject);
var
vDrawing: TsgCADDXFImage; // a class for reading DXF format
I, J: Integer;
// "DXF" in the name of the Line class is used for compatibility
// use this class for lines in all CAD formats

// An insert is a block reference. Several inserts can reference to the same block.
vInsert: TsgDXFInsert;
S: string;
begin
vDrawing := TsgCADDXFImage.Create; //TsgDXFImage is a class for DXF file reading

//Please use a correspond class to read a drawing of other format.

//For example TsgDWGImage for DWG format, TsgCGMImage for CGM, etc.
vDrawing.LoadFromFile('Entities.dxf');
// searching entities in the current layout of the drawing
for I := 0 to vDrawing.CurrentLayout.Count - 1 do
begin
if vDrawing.CurrentLayout.Entities[I].EntType = ceInsert then
begin
vInsert := TsgDXFInsert(vDrawing.CurrentLayout.Entities[I]);
for J := 0 to vInsert.Attribs.Count - 1 do
S := S + TsgDXFAttrib(vInsert.Attribs[J]).Tag + ' = ' +
TsgDXFAttrib(vInsert.Attribs[J]).Value + #13;
ShowMessage('Block name: ' + #13 + vInsert.Block.Name + #13 + S);
end;
S := '';
end;
vDrawing.Free;
end;