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: 

ArrayList Compile error: Sub or Function not define

1 REPLY 1
Reply
Message 1 of 2
snappyjazz
387 Views, 1 Reply

ArrayList Compile error: Sub or Function not define

I'm using Inventor 2019 and using the vba editor. My code is to try and get the child nodes of the content center hierarchy. The code works when looping through and posting a message box at each loop. Now I would like to capture the display name of each child node in a list. However, at the "Dim NodeArrayList As New ArrayList" line I get the compile error. When reviewing that call to online help, it should work. Any suggestions?

 

Sub RecursiveNodes()
    Dim cc As ContentCenter
    Set cc = ThisApplication.ContentCenter
    Dim NodeArrayList As New ArrayList
    
    
'    For Level1 = 1 To cc.TreeViewTopNode.ChildNodes.Count
    For Level1 = 1 To 2
'        MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).DisplayName)
        NodeArrayList.Add (cc.TreeViewTopNode.ChildNodes.Item(Level1).DisplayName)
                For Level2 = 1 To cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Count
'                        MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).DisplayName)
                        NodeArrayList.Add ("    " & cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).DisplayName)
                            For Level3 = 1 To cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Count
'                                MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).DisplayName)
                                NodeArrayList.Add ("    " & "    " & cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).DisplayName)
                                    For Level4 = 1 To cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).ChildNodes.Count
'                                        MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).ChildNodes.Item(Level4).DisplayName)
                                        NodeArrayList.Add ("    " & "    " & "    " & cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).ChildNodes.Item(Level4).DisplayName)
                                    Next
                            Next
                Next
    Next
    
'Message box to verify the hierarchy Dim NodeArrayListVariable As String If NodeArrayList.Count > 0 Then For Each Counter In NodeArrayList NodeArrayListVariable = NodeArrayListVariable & NodeArrayList(Counter) & vbNewLine Next Else MsgBox ("Node Array List wasn't created") End If MsgBox (NodeArrayListVariable) End Sub
1 REPLY 1
Message 2 of 2
snappyjazz
in reply to: snappyjazz

Update:

  • I was able to get the ArrayList created as a variable.
  • The line of code: "NodeArrayList.Add (cc.TreeViewTopNode.ChildNodes.Item(Level1).DisplayName)" gives a runtime error "Object required".  I didn't think it mattered what you added to an array list.
  • So I adjusted this line to: "NodeArrayList.Add (cc.TreeViewTopNode.ChildNodes.Item(Level1))". This is looking directly at the child node object itself. Now I have a runtime error "Object doesn't support this property or method".

Conclusion:

  • Am I setting the ArrayList incorrectly?
  • If I can't add the display name or the object directly to an array list via the ".add" method; is there another way? All the reading I have done supports the way I tried. I am missing something.

 

 

Sub RecursiveNodes()
    Dim cc As ContentCenter
    Set cc = ThisApplication.ContentCenter
    Public NodeArrayList = ArrayList
    

'    For Level1 = 1 To cc.TreeViewTopNode.ChildNodes.Count
    For Level1 = 1 To 2
'        MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).DisplayName)
        
'        NodeArrayList.Add (cc.TreeViewTopNode.ChildNodes.Item(Level1).DisplayName)
NodeArrayList.Add (cc.TreeViewTopNode.ChildNodes.Item(Level1)) For Level2 = 1 To cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Count ' MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).DisplayName) ' NodeArrayList.Add (" " & cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).DisplayName) For Level3 = 1 To cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Count ' MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).DisplayName) ' NodeArrayList.Add (" " & " " & cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).DisplayName) For Level4 = 1 To cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).ChildNodes.Count ' MsgBox (cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).ChildNodes.Item(Level4).DisplayName) NodeArrayList.Add (" " & " " & " " & cc.TreeViewTopNode.ChildNodes.Item(Level1).ChildNodes.Item(Level2).ChildNodes.Item(Level3).ChildNodes.Item(Level4).DisplayName) Next Next Next Next Dim NodeArrayListVariable As String If NodeArrayList.Count > 0 Then For Each Counter In NodeArrayList NodeArrayListVariable = NodeArrayListVariable & NodeArrayList(Counter) & vbNewLine Next Else MsgBox ("Node Array List wasn't created") End If MsgBox (NodeArrayListVariable) End Sub 

 

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

Post to forums  

Autodesk Design & Make Report