Files
STPViewer/tools/SmokeTest/TreeDump.cs
T

33 lines
1009 B
C#

// Print the STEP object hierarchy after import with HierarchyToBlocks enabled.
using CADability;
using CADability.GeoObject;
namespace SmokeTest;
internal static class TreeDump
{
public static void Run(string path)
{
var imp = new ImportStep { HierarchyToBlocks = true };
GeoObjectList list = imp.Read(path);
Console.WriteLine($"top-level objects: {list?.Count}");
if (list is null) return;
foreach (IGeoObject go in list) Dump(go, 0);
}
private static void Dump(IGeoObject go, int indent)
{
string name = go switch
{
Block b => b.Name,
Solid s => s.NameOrEmpty,
Shell sh => sh.NameOrEmpty,
_ => "",
};
Console.WriteLine($"{new string(' ', indent * 2)}{go.GetType().Name} '{name}' children={go.NumChildren}");
if (indent > 6) return;
for (int i = 0; i < go.NumChildren; i++)
if (go.Child(i) is IGeoObject c) Dump(c, indent + 1);
}
}