Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: ngnam1988

Hi @ngnam1988.  Here is an iLogic rule containing a couple of pretty helpful custom Functions to help you find those BrowserNode objects.  Once you have tried it out, you can change the way you set the True/False (expanded/not expanded) setting however you want.  I'm using condensed Try...Catch blocks in this rule, just in case the node is either not found, or not currently visible.  If you can't see it on your screen, then you will likely not be able to expand it.  There are also other useful routines for recursively searching or processing a BrowserNode tree.

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	Dim oModelPane As BrowserPane = GetModelBrowserPane(oDoc)
	Dim oTopNode As BrowserNode = oModelPane.TopNode
	Dim oBlocksNode As BrowserNode = RecursivelyGetBrowserNodeByName(oTopNode.BrowserNodes, "Blocks", True)
	Try : oBlocksNode.Expanded = True : Catch : End Try
	Dim oSolidBodiesNode As BrowserNode = RecursivelyGetBrowserNodeByName(oTopNode.BrowserNodes, "Solid Bodies", True)
	Try : oSolidBodiesNode.Expanded = True : Catch : End Try
	Dim oViewNode As BrowserNode = RecursivelyGetBrowserNodeByName(oTopNode.BrowserNodes, "View:", True)
	Try : oViewNode.Expanded = True : Catch : End Try
	Dim oAnnotationsNode As BrowserNode = RecursivelyGetBrowserNodeByName(oTopNode.BrowserNodes, "Annotations", True)
	Try : oAnnotationsNode.Expanded = True : Catch : End Try
	Dim oOriginNode As BrowserNode = RecursivelyGetBrowserNodeByName(oTopNode.BrowserNodes, "Origin", True)
	Try : oOriginNode.Expanded = True : Catch : End Try
	
End Sub

Function GetModelBrowserPane(oDoc As Document) As BrowserPane
	For Each oPane As BrowserPane In oDoc.BrowserPanes
		If oPane.BuiltIn And oPane.TreeBrowser And _
			(oPane.InternalName = "AmBrowserArrangement" Or _
			oPane.InternalName = "DlHierarchy" Or _
			oPane.InternalName = "PmDefault") Then Return oPane
	Next : Return Nothing
End Function

Function RecursivelyGetBrowserNodeByName(oNodes As Inventor.BrowserNodesEnumerator, sNodeName As String, _
Optional bUseStartsWith As Boolean = False) As Inventor.BrowserNode
	If oNodes Is Nothing OrElse oNodes.Count = 0 Then Return Nothing
	For Each oNode As Inventor.BrowserNode In oNodes
		If bUseStartsWith = True Then
			If oNode.BrowserNodeDefinition.Label.StartsWith(sNodeName) Then Return oNode
		Else
			If oNode.BrowserNodeDefinition.Label = sNodeName Then Return oNode
		End If
		If oNode.BrowserNodes.Count > 0 Then RecursivelyGetBrowserNodeByName(oNode.BrowserNodes, sNodeName, bUseStartsWith)
	Next 'oNode
	Return Nothing
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)