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: 

Incorrect BrowserNode.Parent, method ignores folder belonging to assembly

3 REPLIES 3
Reply
Message 1 of 4
CattabianiI
434 Views, 3 Replies

Incorrect BrowserNode.Parent, method ignores folder belonging to assembly

I'm experiencing this problem that seems a bug, trying to iterate thru assembly structure looking for folders too.

 

TL;DR
Traversing down with BrowserNode.BrowserNodes property works;

Traversing up with BrowserFolder.Parent property doesn't work if this folder is nested in a non active assembly: is this a bug? 

 

Long version with two code snippet, useful for testing.

This is how my algorithm works: for every occurence I get the linked BrowserNode, I check recursively if parents are BrowserFolders and if yes I store them in my structure.

 

If folders belong to the top assembly everything is ok. 

If folders are nested in other assemblies my algorithm doesn't work.

 

I've attached an assembly which structure (considering folders) is the image on the right but what I get is the one on the left:

 

ModelBrowserStructure.PNGAssemblyTreeStructure.PNG

 

Folder named FolderLev2 is missing.

 

The iLogic code to reproduce the issue (same behaviour via .net api and Inventor 2017 and 2018):

SyntaxEditor Code Snippet

Class TraverseAssemblyRule
    
    Const printedTreeFfn As String = "c:\temp\AssemblyTree.txt"
    
    Private Shared _serializedBrowserFolder As Dictionary(Of String, Object)
    
    Sub Main() 
        Dim oAsmDoc As AssemblyDocument 
        oAsmDoc = ThisApplication.ActiveDocument 
    
        _serializedBrowserFolder = New Dictionary(Of String, Object)
        
        Using sw As IO.StreamWriter = IO.File.CreateText(printedTreeFfn)
            sw.WriteLine(oAsmDoc.DisplayName )
        End Using
    
        TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1) 
    End Sub 
        
    Sub PrintFolder(browserNode As BrowserNode, ByRef level As Integer)
        Dim browserFolder As BrowserFolder = TryCast(browserNode.NativeObject, BrowserFolder)
        If browserFolder Is Nothing Then
            Return
        End If

        If Not _serializedBrowserFolder.ContainsKey(browserNode.FullPath) Then            
            PrintFolder(browserFolder.Parent, level)
            
            _serializedBrowserFolder.Add(browserNode.FullPath, Nothing)        
            Using sw As IO.StreamWriter = IO.File.AppendText(printedTreeFfn)
                sw.WriteLine(Space(level*2) + browserFolder.Name)
            End Using
        End If
    
        level = level + 1
    End Sub
    
    Sub PrintOccContaingFolders(occ As ComponentOccurrence, ByRef level As Integer)
        Dim occNode As BrowserNode = ThisDoc.Document.BrowserPanes.Item("AmBrowserArrangement").GetBrowserNodeFromObject(occ)
        If occNode Is Nothing Then
            Return
        End If
    
        Dim parentNode As BrowserNode = occNode.Parent
        If parentNode Is Nothing Then
            Return 
        End If
        
        PrintFolder(parentNode, level)
    
        Return 
    End Sub
            
    Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, level As Integer) 
        Dim oOcc As ComponentOccurrence 
        For Each oOcc In Occurrences 
            Dim startingLevel As Integer = level 
            
            PrintOccContaingFolders(oOcc, level)
            Using sw As IO.StreamWriter = IO.File.AppendText(printedTreeFfn)
                sw.WriteLine(Space(level*2) + oOcc.Name )
            End Using

            If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then 
                TraverseAssembly(oOcc.SubOccurrences, level + 1) 
            End If 
            
            level = startingLevel    
        Next 
    End Sub

End Class

 

 

To get the proper structure I should work directly on the ModelBrowserPane (or adopt a mixed solution) because the BrowserNodes property (that returns a collection of the top level BrowserNode objects contained under this node) works.

  

Here the iLogic code to print the ModelBrowserPane tree as in the image on the right:

SyntaxEditor Code Snippet

Class TraverseBrowserPaneRule
    Const printedTreeFfn As String = "c:\temp\modelBrowser.txt"
    
    Sub Main()
        Dim modelBrowserPane As BrowserPane = ThisApplication.ActiveEditDocument.BrowserPanes.Item("AmBrowserArrangement")
        Dim topNode As BrowserNode = modelBrowserPane.TopNode

        Using sw As IO.StreamWriter = IO.File.CreateText(printedTreeFfn)
            sw.WriteLine(ThisApplication.ActiveEditDocument.DisplayName )
        End Using
        
        PrintModelNodeNameRec(topNode, 0)
    End Sub
    
    Sub PrintModelNodeNameRec(browserNode As BrowserNode, level As Integer) 
        Dim name As String
        If browserNode.NativeObject IsNot Nothing AndAlso browserNode.NativeObject.Type <> ObjectTypeEnum.kBrowserFolderObject  _
        AndAlso browserNode.NativeObject.Type <> ObjectTypeEnum.kComponentOccurrenceObject _
        AndAlso browserNode.NativeObject.Type <> ObjectTypeEnum.kComponentOccurrenceProxyObject _
        AndAlso browserNode.NativeObject.Type <> ObjectTypeEnum.kAssemblyComponentDefinitionObject Then
            Return
        End If
        Try
            name = browserNode.NativeObject.Name
        Catch ex As Exception
            'name = browserNode.FullPath
        End Try
        
        If Not String.IsNullOrEmpty(name) Then
            Using sw As IO.StreamWriter = IO.File.AppendText(printedTreeFfn)
                sw.WriteLine(Space(level*2) + name)
            End Using
        End If

        For Each node As BrowserNode In browserNode.BrowserNodes
            PrintModelNodeNameRec(node, level + 1)
        Next
    
        Return 
    End Sub

End Class

 

 

 

3 REPLIES 3
Message 2 of 4
YuhanZhang
in reply to: CattabianiI

This seems an Inventor API bug, I logged this, thanks for reporting it.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 4
CattabianiI
in reply to: YuhanZhang

Thank you @YuhanZhang,

 

is there an internal issue ID to understand when it is addressed?

 

Message 4 of 4
YuhanZhang
in reply to: CattabianiI

Please provide 10691 to query its status.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report