Skip to main content

Read texts procedure

uses DXF, DXFConv,

...

type

TForm1 = class(TForm)
Image1: TImage;

...

implementation

procedure TForm1.ReadTextsClick(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
vText: TsgDXFText;
vMText: TsgDXFMText;
S: string;
begin
//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 := TsgCADDXFImage.Create;
vDrawing.LoadFromFile('Entities.dxf');
Image1.Picture.Graphic := nil;
Image1.Canvas.StretchDraw(Rect(0, 0,
Round(vDrawing.Width * Image1.Height / vDrawing.Height), Image1.Height), vDrawing);
// searching entities in the current layout of the drawing
for I := 0 to vDrawing.CurrentLayout.Count - 1 do
begin
if vDrawing.CurrentLayout.Entities[I] is TsgDXFText then
begin
vText := TsgDXFText(vDrawing.CurrentLayout.Entities[I]);
ShowMessage('Text: ' + #13 + vText.Text);
end;
if vDrawing.CurrentLayout.Entities[I]is TsgDXFMText then
begin
vMText := TsgDXFMText(vDrawing.CurrentLayout.Entities[I]);
for J := 0 to vMText.Block.Count - 1 do
S := S + TsgDXFText(vMText.Block.Entities[J]).Text + #13;
ShowMessage('MText: ' + #13 + S);
end;
end;
vDrawing.Free;
end;