RhinoCommon nested instances

I’m am attempting to query nested instance in rhino common and find it confusing.

If I have an InstanceReferenceGeometry, I see its Xform property and then it has a ParentIdefId.

I guess I look this up in the RhinoDoc.ActiveDoc.InstanceDefinition but using what method?
Will this look up give me InstanceDefinition objects or InstanceDefinitionGeometry objects?
How to you get the actual geometry objects from an InstanceDefinitionGeometry?

I start with a list of ObjRef

List geometries = GetListFromSomewhere();

        foreach (var objref in geometries)
        {
            if (null != objref.Object())
            {
                    var iref = objref.Object() as Rhino.DocObjects.InstanceObject;
                    if (iref != null)
                    {
                           Transform itransf = iref.InstanceXform;
                           var idef = iref.InstanceDefinition;
                           if (idef != null)
                           {
                                 var inst_obj = idef.GetObjects();
                                 foreach (Rhino.DocObjects.RhinoObject rhObj in inst_obj)
                                  {
                                        Rhino.Geometry.InstanceReferenceGeometry childRef = rhObj.Geometry as Rhino.Geometry.InstanceReferenceGeometry;
                                        if(childRef != null)
                                        {
                                              // Stuck here
                                        }
                                 }
            }

Hi @Tommy_Tucker,

Here are a couple of samples that you might find helpful:

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinocommon/cs/SampleCsCommands/SampleCsDumpBlockTree.cs

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinocommon/cs/SampleCsCommands/SampleCsExplodeBlock.cs

– Dale

2 Likes

Got it. I was looking at the object’s geometry rather than the object.

Thanks for your help. Rhino and RhinoCommon are outstanding.