How to Remove InstanceObject with a InstanceDefinition in Rhino C#

Hi I’m currently encounter a problem removing a InstanceObject within a InstanceDefinition by using ObjectTable.Delete() function. The following script doesn’t work(no error message, but object remains there), I’m wondering why and if there’s a better way to do this?

for (int i = 0; i < instanceDefinitionTable.Count; i++)
    {
      InstanceObject[] insObjArray = instanceDefinitionTable[i].GetReferences(1);

      foreach (InstanceObject insObj in insObjArray )
      {
        int layerIndex = insObj.Attributes.LayerIndex;

        if (layerIndex == 6)
        {
          objectTable.Delete(insObj, false);
        }
      }
    }

Hi @Edward_Lu,

The property way to modify an instance definition is to use InstanceDefinitionTable.ModifyGeometry.

Example:

– Dale