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

Expanded Folder/Node in Part's Model Tree Browser

ngnam1988
Advocate

Expanded Folder/Node in Part's Model Tree Browser

ngnam1988
Advocate
Advocate

Dears,

I'm trying control expand/collapse these folders/nodes in Part (.ipt). Could you please help me. Thanks,

ngnam1988_0-1691517093770.png

 

0 Likes
Reply
Accepted solutions (1)
468 Views
4 Replies
Replies (4)

WCrihfield
Mentor
Mentor
Accepted solution

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)

ngnam1988
Advocate
Advocate

You're super! @WCrihfield 
Thank you very much!

0 Likes

Maxim-CADman77
Advisor
Advisor

With all respect, there is at least one uncertainty,
Origin BrowserFolder is not guaranteed to have the label "Origin" even in English UI (believe or not but it is user customizable - one can rename it after just two clicks!!).

Professional code should not rely on customizable Label. I suggest to use something like:

Dim origWPt = oDoc.ComponentDefinition.WorkPoints(1)

Dim origWPtNBND As NativeBrowserNodeDefinition = oDoc.BrowserPanes.GetNativeBrowserNodeDefinition(origWPt)
Dim origWptNode As BrowserNode = topNode.AllReferencedNodes(origWPtNBND).Item(1)

Dim oOriginNode As BrowserNode = origWptNode.Parent

 

Please vote for Inventor-Idea Text Search within Option Names

WCrihfield
Mentor
Mentor

Hi @Maxim-CADman77.  I like the general idea you are pointing out here.  That route would be pretty safe for getting the 'Origin' folder, since there will always be those original work features in every 'model' document.  When going that route, would likely want to include a check to make sure this is a mode document (part or assembly, not a drawing) before attempting to dig into its ComponentDefinition to access features.  And with the other folders inquired about here, we would most likely want to check the Count of each SketchBlocks, SurfaceBodys, DesignViewRepresentations, and ModelAnnotations type collections to make sure there is at least one, then attempt to get the first item of that type, then use that item to get its browser node, then get that node's parent node.  The Blocks & Annotations folders do not even show up until we include some of those types of objects in the document.  And there seems to be some sort of limitation when it comes to getting either the BrowserNode or the NativeBrowserNodeDefinition for the first SurfaceBody object, because it usually fails for me, and throws an 'Unspecified Error' type exception (COMException - EFail).  Also had problems going that route to get the DesignViewRepresentations folder node (no error/exception, just did not work).

 

(I attached a text file containing some modified iLogic rule code I quickly threw together for testing purposes, to do this forum topic task (expand multiple specific browser folders) from a bottom > up approach (get node, then get parent, then expand it).  It seems to work OK for expanding the 'Blocks', 'Annotations', and 'Origin' nodes, but is not working for 'Solid Bodies' or 'View' nodes so far.

 

I agree that 'professional' code should not rely on an unstable aspect of an object to find it, such as its name when that name is user changeable and changes with language, but I was not really developing a 'professional' code (like for a standalone Windows App I was planning on selling) at that time, just a working iLogic rule solution to a forum user request, which was posted within 30 minutes of the request.

 

Plus, I did not realize at the time that the 'Origin' folder could be renamed.  It seems to me like this was not always possible, but in all the years I have been using Inventor, I have never wanted or needed to rename that folder, and have never seen anyone else want or need to rename it.  I did check within the 'What's New' documentation for the last few major releases of Inventor, but did not see any mention of this specific ability changing, so I do not know when it became available.  If someone is using an installation of Inventor other than English, but they understand English enough to read this post, and want to copy and use my code from above, it should be fairly clear that they could change the "Origin" text (and others) to some other text within the Sub Main area.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)