Iterate through weldment suboccurence and get fulldocument name

Iterate through weldment suboccurence and get fulldocument name

guillaume.canor
Explorer Explorer
375 Views
2 Replies
Message 1 of 3

Iterate through weldment suboccurence and get fulldocument name

guillaume.canor
Explorer
Explorer

Hello everyone,

 

I'm having a problem with an API I'm wirting. I'm iterating through an assembly to get iProperties and fulldocumentname of each occurence. In fact, the routine goes well exept when I'm adding a weldment subassembly (normal subassembly do no wrong). Here is the base code i'm using to do that :

 

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer)
' Iterate through all of the occurrence in this collection.  This
' represents the occurrences at the top level of an assembly.
  Dim oOcc As ComponentOccurrence
   For Each oOcc In Occurrences
    Dim oOccPath As String = oOcc.ReferencedDocumentDescriptor.FullDocumentName

 'Check to see if this occurrence represents a subassembly
 'and recursively call this function to traverse through it.
    If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
         Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
     End If
   Next
End Sub

 

With this code, I get the weldment path but not the one of the parts in it. The program gives me an error because oOcc.ReferencedDocumentDescriptor.FullDocumentName is nothing which I don't understand. 

 

I hope someone can help me. I am at a loss there.

 

Thanks,

 

0 Likes
Accepted solutions (1)
376 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

In a weldment assembly, the welds are also occurrences. (That is a bit counter-intuitive) Because weld are virtual parts there is no referenced document. (This also implies that you will run in trouble if you have virtual parts in a normal assembly.) Try this:

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    For Each oOcc As ComponentOccurrence In Occurrences
        If (oOcc.ReferencedDocumentDescriptor Is Nothing) Then
            MsgBox(oOcc.Name & " has none refrence document")
            Continue For
        End If

        'Check to see if this occurrence represents a subassembly
        'and recursively call this function to traverse through it.
        If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
        End If
    Next
End Sub

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

guillaume.canor
Explorer
Explorer

Thank for the quick  and well explained answer. That resolved my problem 🙂

0 Likes