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: 

Get Inventor TreeView in VB.net Customised

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
amitnkukanur
1680 Views, 4 Replies

Get Inventor TreeView in VB.net Customised

Am trying to get the treeview filled with Inventor Treeview details which is present on lrft side.

 

 

this is the code i did

 

Imports System.Uri

Imports System.UriComponents

Imports System.UriParser

 

 

Public objAppServComponent AsNew Inventor.ApprenticeServerComponent

Dim objAppServDoc As Inventor.ApprenticeServerDocument

 

 

objAppServDoc = objAppServComponent.Open(TextBox1.Text) '''' here i get path of assembly

Dim objTreeNode As New TreeNode(objAppServDoc.DisplayName)

TreeView1.Nodes.Add(objTreeNode)

Call GetComponents(objAppServDoc.ComponentDefinition.Occurrence, objTreeNode)

 

''''''Getting error on this above line

'''''' reference to Reference to non shared member requires object reference

 

How to Solve or get Inventor Treeview to customised treeview, any suggestions

Senior Software Engineer
4 REPLIES 4
Message 2 of 5
leefsma
in reply to: amitnkukanur

Hi amitk_189,

 

The "ComponentDefinition.Occurrence" property does not exist, so it is no wonder that the code you provided generates an error.

 

Below is a VB.Net sample that illustrates how to parse an assembly structure using a recursive procedure (this Inventor, but adapting it to Apprentice should be straightforward):

 

    Public Sub AssemblyTraversal()

        Dim oDoc As AssemblyDocument
        oDoc = _InvApplication.ActiveDocument

        'Call the recursive function to iterate through the assembly tree
        Call AssemblyTraversalRec(oDoc.ComponentDefinition.Occurrences, 0)

    End Sub

    Private Sub AssemblyTraversalRec(ByVal InCollection As ComponentOccurrences, ByVal level As Long)

        'Iterate through the components in the current collection
        Dim oCompOccurrence As ComponentOccurrence
        For Each oCompOccurrence In InCollection

            Dim str As String = String.Empty

            If oCompOccurrence.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

                str = Space(3 * level) & " - [Asm]  " & oCompOccurrence.Name

            Else

                str = Space(3 * level) & " - [Part] " & oCompOccurrence.Name

            End If

            Debug.WriteLine(str)

            'Recursively call this function for the sub-occurrences of the current component
            Call AssemblyTraversalRec(oCompOccurrence.SubOccurrences, level + 1)

        Next

    End Sub

 

I hope it helps.

 

 

Philippe Leefsma
Developer Consultant
Developer Technical Services
Global Subscription & Support
 

Autodesk EMEA

 

www.autodesk.com/joinadn

 

 

Message 3 of 5
amitnkukanur
in reply to: amitnkukanur

Getting error on

oDoc = _InvApplication.ActiveDocument

 

Object reference not set to an instance of an object.

 

 

Senior Software Engineer
Message 4 of 5
amitnkukanur
in reply to: amitnkukanur

Hi i solved that error using the below code

 

Dim

Dim _InvApplication As Inventor.Application

Dim InvType AsType = GetTypeFromProgID("Inventor.Application", True)

_InvApplication = CreateInstance(InvType)

 

 

Dim oDoc As Inventor.AssemblyDocument

oDoc = _InvApplication.ActiveDocument

'Till here its working but getting error on next line.

Call AssemblyTraversalRec(oDoc.ComponentDefinition.Occurrences, 0)

Senior Software Engineer
Message 5 of 5
spascual
in reply to: amitnkukanur

Hi Sirs,

 

Could you paste the code you wrote ????

 

Thanks,

 

 

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

Post to forums