ChrisClems / EdgeSharp

A library of helpers and extensions for the Solid Edge API. A spiritual successor to SolidEdge.Community build on modern .NET to make Solid Edge interop less frustrating.
MIT License
1 stars 0 forks source link

Recursively find document from any object by walking parent tree until condition is met #19

Closed ChrisClems closed 1 month ago

ChrisClems commented 1 month ago

Some objects provide a Document property to get the SE document easily. This is useful for accessing helper methods like the various measuring methods. Other types do not provide this property but when walking the parent properties up the list should always eventually end up at the document level. Provide a helper method which will take an arbitrary object and return the first part or sheet metal document in the tree while walking the parent properties recursively.

private static SheetMetalDocument GetParentDocFromObject(object seObject)
    {
        dynamic comObject = seObject;
        var parent = comObject.Parent;
        Console.WriteLine(parent.Type);
        var parentType = (SolidEdgeConstants.DocumentTypeConstants)parent.Type;
        if (parentType is SolidEdgeConstants.DocumentTypeConstants.igSheetMetalDocument)
        {
            var parentDoc = (SheetMetalDocument)parent;
            Console.WriteLine(parentDoc.Name);
            return parentDoc;
        }
        return GetParentDocFromObject(parent);
    }

Decide where to put it in the API based on scope (how many document types to support? Allow arbitrary types to be passed?)

ChrisClems commented 1 month ago

Closed by b9e93d30949753c4394595a5a244f7d436c8889d with initial implementation as a simple helper function. May expand later into extensions if practical but this is the best solution at the moment.