How to get a tree structure of any supported drawing file?
To get a tree structure of any drawing file (IGES, DWG, DXF, etc.) for visualization with a tree component (for example, TTreeView
), you need to iterate through entities in the given file and add each entity to the structure using the following recursive procedure.
uses
..., ComCtrls;
type
tvStructure: TTreeView;
...
implementation
...
procedure Add(AParent: TTreeNode; AEnt: TsgDXFEntity);
var
I: Integer;
begin
if Assigned(AEnt) then
begin
AParent := tvStructure.Items.AddChildObject(Parent, AEnt.EntName, AEnt);
Application.ProcessMessages;
for I := 0 to AEnt.Count - 1 do Add(AParent, AEnt[I]);
end;
end;
The Entities[const AIndex: Integer]: TsgDXFEntity read GetEntity; default
property has the default
directive. That's why you can use the property in a more convenient way like AEnt[I]
instead of AEnt.Entities[I]
.