Hi everyone,
I’m working with nested blocks (InstanceDefinitions / InstanceObjects) in RhinoCommon and I’m running into conceptual trouble identifying the correct way to delete nested instances while preserving block hierarchy.
My scenario
I have the following block structure:
Block A (InstanceDefinition)
├─ InstanceReference → ChildBlock1
│ └─ Geometry
├─ InstanceReference → ChildBlock2
│ └─ Geometry
└─ Geometry (inside Block A)
In the model, there may be multiple instances of Block A.
Goal
Given an InstanceObject that represents ChildBlock1, I want to:
-
If ChildBlock1 is top-level → delete it directly
-
If ChildBlock1 is nested inside Block A:
-
If Block A contains multiple child instances → remove only ChildBlock1 from Block A’s InstanceDefinition
-
If ChildBlock1 is the only remaining child → delete the parent instance of Block A instead
-
-
Avoid flattening geometry or corrupting nested block structure
What I’m doing so far
-
I rebuild the parent
InstanceDefinitionusingInstanceDefinitions.ModifyGeometry(...) -
I correctly recreate nested references using
InstanceReferenceGeometry(def.Id, instanceRef.InstanceTransform) -
This part works as expected when removing one child from a definition
Where I’m stuck
When ChildBlock1 is the last child inside its parent definition, I need to delete the parent InstanceObject, not the definition.
However, I’m unable to reliably find the InstanceObject of the parent definition that contains the current instance.
I tried approaches like:
parentDefinition.GetReferences(1)
but this only returns instances of the definition — it does not tell me which instance contains the nested child.
I currently maintain my own block-containment graph (definition → parent definitions), but I still can’t determine which parent instance should be deleted in this case.
My questions
-
Is there a recommended RhinoCommon pattern for navigating upward in nested block hierarchies (instance → parent instance)?
-
Is maintaining a custom block graph the only correct approach?
-
Is there any supported way to determine which
InstanceObjectcontains a given nestedInstanceObject?
Any guidance or confirmation of the correct approach would be greatly appreciated.