Get used InstanceDefinition for a InstanceDefinition

Hi all,

is there a way to get the whole InstanceDefinitions for a block and there coresponding structure.

The method InstanceDefinition.GetContainers return a list of all the InstanceDefinitions that contain a reference of this InstanceDefinition.

This means a nested InstanceDefinition lists all InstanceDefinition that use this InstanceDefinition but the top level InstanceDefinition that use all this referenced InstanceDefinition return a empty array if the InstanceDefinition.GetContainers is used.

What i want is a top to bottom structure of the InstanceDefinitions not the other way.

Maybe i could inverse the GetConatiner array but befor i can do so i need to compare all these arrays for similar InstanceDefinitionObjects.

Ideas are welcome.

HI @flokart ,
This would be one way to get a List of all nested InstanceDefinitions inside a parent definition (irrespective of their nesting order)

public List<InstanceDefinition> GetInternalDefinitions(InstanceDefinition iDef)
        {
            var internalObjects = iDef.GetObjects();

            List<InstanceDefinition> internalDefs = new List<InstanceDefinition>();

            foreach (RhinoObject rObj in internalObjects)
            {
                if (rObj is InstanceObject iObj)
                {
                    if (!internalDefs.Contains(iObj.InstanceDefinition))
                    {
                        internalDefs.Add(iObj.InstanceDefinition);

                        foreach (InstanceDefinition subDef in GetInternalDefinitions(iObj.InstanceDefinition))
                            if (!internalDefs.Contains(subDef))
                                internalDefs.Add(subDef);
                    }
                }
            }
            return internalDefs;
        }