VB Blocks inside blocks

I am trying to write a VB RhinoScript that finds objects with certain usertext associated with my Weight Estimating system, then show and select them. That part is easy. I also look through each block definition for a qualifying object, then show and select all instances of that block. So far so good. BUT, a qualifying block instance could itself be buried inside another block definition, which could be shown by another instance! The tree of block definitions and instances can get so convoluted I can’t seem to figure out how to get them all shown and selected. Is there a way to do this with VB?

arrBlocks = Rhino.BlockIds 'these are block definitions, not instances!
If Isarray(arrBlocks) Then
For Each strBlock In arrBlocks

	If Rhino.IsBlock(strBlock) Then					
		boolHasWtObjects = False 'default
		arrObjects = Rhino.BlockObjects(strBlock)
		If IsArray(arrObjects) Then
							
			'Determine If any objects with weight Userdata are In the block definition
			For Each strObject In arrObjects
				If Rhino.IsObject(strObject) Then
					If WeightObjectType(strObject) <> 0 Then boolHasWtObjects = True
				End If
			Next
							
			If boolHasWtObjects Then			
				'Turn on all layers of objects in the block definition
				For Each strObject In arrObjects
					If Rhino.IsObject(strObject) Then
						strLayer = Rhino.ObjectLayer(strObject)
						Call LayerOnOff(strLayer, True, True) 'parents too
						Rhino.ShowObject strObject
					End If
				Next

				'Show all the block instances that use this block
				arrBlockInstances = Rhino.BlockInstances(strBlock)
				If isarray(arrBlockInstances) Then
					For Each strBlockInstance In arrBlockInstances
						strLayer = Rhino.ObjectLayer(strBlockInstance)
						Call LayerOnOff(strLayer, True, True) 'parents too
						Rhino.ShowObject strBlockInstance									
					Next
				End If
								
				THIS IS WHERE I GET STUCK
				What about qualifying objects inside blocks inside blocks inside blocks!
			End If		
		End If
	End if
Next

End If

I’ve revisited this and come really close using recursion to handle the blocks in blocks. It finds all objects buried in multiple block levels, and turns on the associated layers. It does manage to show (unhide) top level blocks, but it does not show (unhide) blocks made up of other blocks. For some bizarre reason the Rhino.ShowObject procedure only works for blocks without other block instances inside it. When I have it report the block instances it is working with, the buried block instances have completely different IDs than reported by the “WHAT” command (from before two blocks were blocked into one).

How do I get this to show (unhide) block instances that have other block instances inside them?

Private Function ShowWtObjectsInBlockInstance(strBlockInstance) 'returns the number of Wt objects found in the instance
Dim strBlock, arrObjects,strObject
Dim lngCount, strLayer

lngCount = 0
If Rhino.IsBlockInstance(strBlockInstance) Then
	Rhino.MessageBox "Looking at block instance: " + Rhino.BlockInstanceName(strBlockInstance) + " = " + strBlockInstance

	strBlock = Rhino.BlockInstanceId(strBlockInstance)
	If Rhino.IsBlock(strBlock) Then
		arrObjects = Rhino.BlockObjects(strBlock)'array of objects in the block
		If IsArray(arrObjects) Then
			For Each strObject In arrObjects
				If WeightObjectType(strObject) <> 0 Then '< my routine to identify Weight Item from UserData
					
					lngCount = lngCount + 1
					'Rhino.Messagebox cstr(lngCount) + ": " + strObject
					
					Rhino.ShowObject(strBlock)
					
					'Show block instance & turn on it's layer
					strLayer = Rhino.ObjectLayer(strBlockInstance)						
					Call LayerOnOff(strLayer, True, True) 'parents too
					'Rhino.Messagebox "Layer turned on: " + Rhino.LayerName(strLayer)							
					Rhino.ShowObject strBlockInstance
					Rhino.Messagebox "Block Instance shown: " + strBlockInstance	

					'show object & turn on it's layer 
					strLayer = Rhino.ObjectLayer(strObject)
					Call LayerOnOff(strLayer, True, True) 'parents too
					'Rhino.Messagebox "Layer turned on: " + Rhino.LayerName(strLayer)										
													
				ElseIf Rhino.IsBlockInstance(strObject) Then 'Need to use recursion!
					lngCount = lngCount + ShowWtObjectsInBlockInstance(strObject)

				End If
			Next						
		End If
	End If
End If
ShowWtObjectsInBlockInstance = lngCount

End Function

Nevermind, I figured out a solution.

What was the solution?