Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - Move browser panel folders to the top

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
matt_jlt
1151 Views, 3 Replies

iLogic - Move browser panel folders to the top

Hopefully someone can help me because i'm really stuck on this one. I am trying to write some code to move all the top level folders, to the top of the browser panel in an assembly. (i said top level because there can be sub folders sometimes and i just want the leave them where they are under the top level folder)

 

I am getting very weird results and nothing seems to work. Can someone help me out please?

 

First Issue

When trying to check the native object type under the node. Ilogic + vba just throw an error. it doesn't seem to recognise "NativeObject" although it's there in the object browser in VBA. see below for excerpt i think should work but doesn't

 

	If oBN.NativeObject.Type = ObjectTypeEnum.kBrowserFolderObject Then
		'Do something
	End If

To get around this, i added all of the folder names to a list then do a compare on the "BrowserNodeDefinition.Label " which seems to work ok.

 

 

Second Issue

I am using the "End of part" node, that seems to always be the last node before the first assembly occurrence but when i try and re-order the browser tree it randomly moves the folders around and crashes if a folder is at the top of the browser. I have tried inserting the new positions before / after the first browser node but nothing seems to work.

 

Any ideas would be much appreciated.

 

I am using Inventor 2019 Pro / Windows 10

 

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oBP As BrowserPane = oDoc.BrowserPanes.Item("Model")

' Check there are folders in the browser
If oBP.TopNode.BrowserFolders.Count = 0 Then
	MessageBox.Show("There are no folders in this assembly", "test")
	Exit Sub
End If

Dim myList As New List(Of String)
For Each oBF As BrowserFolder In oBP.TopNode.BrowserFolders
	myList.Add(oBF.Name)
	
Next

Dim i As Integer = 5
Dim intEnd As Integer = 0

For i = 1 To oBP.TopNode.BrowserNodes.Count
	If oBP.TopNode.BrowserNodes.Item(i).BrowserNodeDefinition.Label = "End of Features" Then
		Logger.Info("End Node found")
		' Found end node, now save the index number
		intEnd = i
	End If
Next

' Iterate through top level nodes only (does not go into sub folders)
For Each oBN As BrowserNode In oBP.TopNode.BrowserNodes
	If myList.Contains(oBN.BrowserNodeDefinition.Label) Then
		oBP.Reorder(oBN, True, oBP.TopNode.BrowserNodes.Item(intEnd+1))
	End If

Next

Thanks, Matt.

 

3 REPLIES 3
Message 2 of 4
HideoYamada
in reply to: matt_jlt

Hi Matt,

 

As you said, moving the node to the next of EndOfFeature cause runtime error.

I thought it is because of visibility (EndOfFeature is invisible normally), so tried to move to the next of Origin, but the result was same.

 

Thus, you should move the node to the upper of the first occurrence node.

I wrote the code in VBA. Can you translate this to iLogic? (Needs help?)

Option Explicit

Sub MoveFolderNodesToTop()
    Dim oAssyDoc As AssemblyDocument
    Set oAssyDoc = ThisApplication.ActiveDocument
    Dim oModelPane As BrowserPane
    Set oModelPane = oAssyDoc.BrowserPanes("AmBrowserArrangement")
    Dim oTopNode As BrowserNode
    Set oTopNode = oModelPane.TopNode
    
    ' Find next of EndOfFeatures
    Dim oFirstOccurrenceNode As BrowserNode
    Set oFirstOccurrenceNode = Nothing
    Dim lowerOfEndOfFeatures As Boolean
    lowerOfEndOfFeatures = False
    Dim oNode As BrowserNode
    For Each oNode In oTopNode.BrowserNodes
        ' Sometimes NativeObject is Nothing.
        ' So you must check it is Nothing or not before accessing it.
        If Not oNode.NativeObject Is Nothing Then
            If Not lowerOfEndOfFeatures Then
                If TypeOf oNode.NativeObject Is EndOfFeatures Then
                    lowerOfEndOfFeatures = True
                End If
            Else
                If Not TypeOf oNode.NativeObject Is BrowserFolder Then
                    Set oFirstOccurrenceNode = oNode
                    Exit For
                End If
            End If
        End If
    Next oNode
    
    ' This means all of top nodes consist of the BrowserFolders.
    If oFirstOccurrenceNode Is Nothing Then
        Exit Sub
    End If
    
    ' Move the folders to upper of oFirstOccurrenceNode
    Dim oBrowserFolder As BrowserFolder
    For Each oBrowserFolder In oTopNode.BrowserFolders
        oModelPane.Reorder oFirstOccurrenceNode, True, oBrowserFolder.BrowserNode
    Next oBrowserFolder
End Sub

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 3 of 4
matt_jlt
in reply to: HideoYamada

Thanks Hideo, that works perfectly. I think one of the key things i was missing was that the Native Object could be nothing and i wasn't expecting that / didn't notice the issue.

 

Thanks Again. Matt.

Message 4 of 4
_dscholtes_
in reply to: HideoYamada


@HideoYamada wrote:

Thus, you should move the node to the upper of the first occurrence node.


And when you don't have any occurrence nodes, just temporary create a virtual component and use its node.

(I came across this "theoretical" situation recently)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report