The following example demonstrates how to find a block by name. Requires the "DXF" and the "DXFConv" units added to the "uses" section.
procedure TForm1.FindBlockClick(Sender: TObject);
var
vDrawing: TsgCADdxfImage; //requires the "DXF" unit added to the "uses" section
I: Integer;
BlockName: string;
begin
vDrawing := TsgCADDXFImage.Create; //TsgDXFImage is a class for DXF file reading
vDrawing.LoadFromFile('Entities.dxf');
BlockName := 'Block1'; // The block name is Block1
for I := 0 to vDrawing.Converter.Counts[csBlocks] - 1 do
if Lowercase(vDrawing.Blocks[I].Name) = Lowercase(BlockName) then
begin //found
ShowMessage(Format('Block with name "%s" was found.' + #13#10 +
'Index of the block is %d', [BlockName, I]));
Break;
end;
vDrawing.Free;
end;
Go to CAD VCL Enterprise