Get list of all parts from assembly using apprentice server

Get list of all parts from assembly using apprentice server

danijel.radenkovic
Collaborator Collaborator
561 Views
3 Replies
Message 1 of 4

Get list of all parts from assembly using apprentice server

danijel.radenkovic
Collaborator
Collaborator

Hello,

 

I am working on my first addin and I need to get list of parts (their filenames) from an assembly which I chose using file open dialog.

 

Thanks in advance friends

Danijel.

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
562 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hi Daniel,

 

Here is the code you need

 

Sub test()
   Dim nModel As AssemblyDocument
   Set nModel = ThisApplication.ActiveDocument

 

   Dim nDocEnum As DocumentDescriptorsEnumerator
   Set nDocEnum = nModel.ReferencedDocumentDescriptors

 

   For Each Item In nDocEnum
     Debug.Print Item.FullDocumentName
   Next Item

End Sub

 

You need to open Immediate window (Ctrl+G) to see result.

 

Regards

Nedeljko.

 

0 Likes
Message 3 of 4

danijel.radenkovic
Collaborator
Collaborator

Hello Nedeljko,

 

This should works when I put code into ilogic rule or inventor vba, but I need to manage with Inventor properties without opening Inventor, using apprentice server.

 

 I think I am close to the solution with this:

 

 For Each n As Inventor.ComponentOccurrence In apprenticeDoc.ComponentDefinition.Occurrences
      lablel.Text = apprenticeDoc.ComponentDefinition.Occurrences(Name).ToString
 Next

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 4 of 4

danijel.radenkovic
Collaborator
Collaborator

Finaly, I resolved with this code.

 

  For Each occ As Inventor.ComponentOccurrence In apprenticeDoc.ComponentDefinition.Occurrences
                If occ.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
                End If
                ListBox1.Items.Add(occ.Name)
 Next

 

Thanks for your help Nedeljko

 

Best regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes