reference a document from Partlist in IDW

reference a document from Partlist in IDW

^_^clovis^_^
Advocate Advocate
463 Views
4 Replies
Message 1 of 5

reference a document from Partlist in IDW

^_^clovis^_^
Advocate
Advocate

Hello,

 

I'm trying to retrieve a document (part/assy) to get its info, from the Partlist in an IDW. But I get this error.

Sometimes it works (with some assy) but never with a single part

 

Sub IndexPartslist()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oPL As PartsList
    Set oPL = oSheet.PartsLists.Item(1)
    
    Dim drawBomRow As DrawingBOMRow
    Dim oBomDoc As Document
    Dim oPLRow As PartsListRow
    Dim i As Integer: i = 1
    
    For Each oPLRow In oPL.PartsListRows
        Debug.Print oPLRow.Item("ITEM").Value
        Set drawBomRow = oPLRow.ReferencedRows.Item(1)
        Set oBomDoc = drawBomRow.BOMRow.ComponentDefinitions.Item(1).Document 'ERROR line
    Next
End Sub

 

Any help would be greatly appreciated

Thanks

0 Likes
Accepted solutions (1)
464 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Sorry, wrong account

 

0 Likes
Message 3 of 5

frederic.vandenplas
Collaborator
Collaborator
Accepted solution

Sorry, previously posted on my other account!


You better check the referenceddocumenttype before traversing the partslist (assembly or part)
 

Sub IndexPartslist()
    
Dim oDoc As DrawingDocument
    
Set oDoc = ThisApplication.ActiveDocument
    
    
Dim oSheet As Sheet
    
Set oSheet = oDoc.ActiveSheet
    
    
Dim oPL As PartsList
    
Set oPL = oSheet.PartsLists.Item(1)
    
    
Dim drawBomRow As DrawingBOMRow
    
Dim oBomDoc As Document
    
Dim oPLRow As PartsListRow
    
Dim i As Integer: i = 1
    
If oPL.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
        
For Each oPLRow In oPL.PartsListRows
            
Debug.Print oPLRow.Item("ITEM").Value
            
Set drawBomRow = oPLRow.ReferencedRows.Item(1)
            
Set oBomDoc = drawBomRow.BOMRow.ComponentDefinitions.Item(1).Document 'ERROR line
        
Next
    ElseIf oPL.ReferencedDocumentDescriptor.ReferencedDocumentType = kPartDocumentObject Then
        
For Each oPLRow In oPL.PartsListRows
            
Set oBomDoc = oPLRow.Item(1).Parent.ReferencedDocumentDescriptor.ReferencedDocument
        
Next
    
End If

End Sub
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 4 of 5

^_^clovis^_^
Advocate
Advocate

Thank you very much!

I'll try your big help after the usual work activity.

Also I'll have to check this

 

ReferencedDocumentDescriptor

 function.

I never saw it before.

Thanks again!

0 Likes
Message 5 of 5

^_^clovis^_^
Advocate
Advocate

Hello Frederic,

That's it

 

Set oBomDoc = oPLRow.Item(1).Parent.ReferencedDocumentDescriptor.ReferencedDocument

Thanks for your help!

0 Likes