Access objects inside blocks using ObjectEnumeratorSettings?

Is it possible to access objects inside blocks using ObjectTable.GetObjectList(ObjectEnumeratorSettings)?

I’m trying to get all breps on a certain layer, whether they’re inside a block or not. I tried using ObjectEnumeratorSettings.IdefObject = true, but that doesn’t work (I think because I want objects inside an instance reference, not a definition).

Is there any way to do this without iterating through all blocks in my model and using InstanceObject.Explode to look at their constituent objects?

Hi @carlRTC,

An instance reference (IRef) does not have any geometry. An IRef references an instance definition (IDef), which maintains a list of instance definition geometry. The IRef also has a transformation that is used to draw the IDef’s instance definition geometry in the correct location.

To iterate for of all the Breps maintained by IDefs, then you can something like this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var filter = new ObjectEnumeratorSettings
  {
    NormalObjects = false,
    LockedObjects = false,
    IdefObjects = true,
    ActiveObjects = true,
    ReferenceObjects = true,
  };
  filter.ObjectTypeFilter = ObjectType.Brep;

  var objectList = doc.Objects.FindByFilter(filter);
  foreach (var obj in objectList)
  {
    RhinoApp.WriteLine("ObjectType: {0}, IsInstanceDefinitionGeometry = {1}", 
      obj.ObjectType, 
      obj.IsInstanceDefinitionGeometry
      );
  }

  return Result.Success;
}

Hope this helps.

– Dale