Hi, I do not take it as a colleague offense, on the contrary, it's an honor for me to collaborate with @mcgyvr , look at your level, I've learned a lot from your contributions, it's one of my teachers in this forum!
Returning to the problem in question here I send you another code, it is probably incomplete, but it may help you to add things. It is another approach, accessing the BOM and trying to capture the quantity of the row, if it is an assembly, it will look for the assembly in "model data" and if it is only part it will search in "only parts"
Sub main
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim doc As Document
myCount = 0 'create a counter
Dim searchTerm As String = InputBox("Search text in Part Number", "Find text", "Default Entry")
For Each doc In openDoc.AllReferencedDocuments
Dim oPartNumber As String = doc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
If InStr(1, oPartNumber, searchTerm) > 0 Then
myCount = myCount+1 'if found increment counter by 1
MessageBox.Show(doc.DisplayName, "FileName")
MessageBox.Show(doc.FullFileName, "FullFileName")
MessageBox.Show(myCount, "Count")
Search_Doc(doc)
End If
Next
End Sub
Sub Search_Doc(doc As Document)
Dim oModelname As String = doc.DisplayName
Dim oDoc As Document
oDoc = ThisDoc.Document
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
' Set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
' Make sure that the parts only view is enabled.
oBOM.PartsOnlyViewEnabled = True
If doc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item(1)'BOM Model data
Call ListItems(oBOMView.BOMRows, 0, oModelname)
End If
If doc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item(3)'BOM only parts
Call ListItems(oBOMView.BOMRows, 0, oModelname)
End If
End Sub
Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer,oModelname As String)
Dim oBOMRow As BOMRow
For Each oBOMRow In Rows
Dim rDoc As Inventor.Document
rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
Dim rDocName As String = rDoc.DisplayName
If rDocName <> oModelname Then
If Not oBOMRow.ChildRows Is Nothing Then
Call ListItems(oBOMRow.ChildRows, indent + 1,oModelname)
End If
Else
If rDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then oType = "Assembly_Quantity: "
If rDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then oType="Part_Quantity: "
oQty = oBOMRow.ItemQuantity
MessageBox.Show(oType & oQty ,"Total quantity")
End If
Next
End Sub
I hope it helps to solve the problem
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn