Sub-object selection in nested blocks - index inconsistency?

Hello all,

I have a Grasshopper script to select a polyline (via Rhino) inside a block, that uses the GeometryComponentIndex property (https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.objref/geometrycomponentindex#) to get the index of the sub-object inside the block.

The script works fine for simple blocks, but for blocks containing nested blocks (in this case, a block made from the composition of a simpler block), the property returns a value that is inconsistent with the geometry obtained using the Explode Object (in Recursive mode) + Model Object components.

In the attached example, when you select an “L” shaped curve from the simple block, the index is consistent (black+white highlight overlap), but not so when you try the same with the nested block.

Is there a way to get a consistent index for the sub-object?

Also: I am trying to extract the selected curve layer, but with the nested block I can only access the nested block sub-object to find its layer (although I can extract the curve geometry). Is there a way of getting the curve layer no matter the nesting level of the block it belongs to?

IMPORTANT: apologies in advance, but to test this you’ll need to install Synapse first (available from the Packagemanager). I tried to make the script pure GH, but if I use a button or trigger instead of a UI button, afterwards I can no longer interact with the mouse in Grasshopper.

In the picture below: selected curve in white, geometry corresponding to the extracted index in black.

GeometryComponentIndex issue.3dm (104.0 KB)
GeometryComponentIndex issue.gh (32.2 KB)