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

1 Like

@dale , I ended up not using an Object Enumerator in this case, but your clarification of IRefs vs. IDefs helped immensely.

I have a further question about objects inside blocks. Is it possible to hide only some, not all, of the individual objects in a block in a detail view, without using layers? I haven’t tried it programmatically yet, but I clicked into a detail view, double clicked a block to edit it, selected a polysurface, and ran the HideInDetail command. Although I no longer could select the polysurface, it still stayed visible in the detail view, even after exiting the block editor. Am I missing something?

Thank you!