I have lost a bit, so I apologize if this contribution does not help.
I modified an ilogic rule that I had, maybe it could serve as an approach to a possible solution. This rule is executed in an assembly.
Supposedly, this rule searches in each reference file, if it is a part it will take the amount of the BOM only parts, and if it is an assembly it will take the amount of the BOM model data, it will search among its children until finding the assembly.
Create in a notebook first the quantity, then the name of the file, then the description, and finally the partnumber. I suppose that looking for a similar approach could reach the desired result. regards
Public Class RWEI_0001A
Shared oTextSave As String = "C:\Users\Public\Documents\iLogicBuffer.txt"
Sub Main()
Dim oDashes As String = ""
Dim iL_NO As String = "RULENAME"
Dim iL_Name As String = "EXPORT Flattened Bill of material"
Dim iL_FullName As String = "Rule " & iL_NO & ": " & iL_Name
Dim oDoc As Document = ThisApplication.ActiveDocument
oDelete_ex_Notepad(oTextSave, iL_NO)
oHL1 = "FILE REFERENCE TREE RAN FROM: " & oDoc.FullFileName
oWrite_HeaderLines(oTextSave, oHL1)
oHL2 = iL_FullName
oWrite_HeaderLines(oTextSave, oHL2)
For i = 1 To Len(iL_FullName)
oDashes = oDashes & "-"
Next i
oWrite_DashLine(oTextSave, oDashes)
' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisDoc.Document
Dim oBOM As BOM
oBOM = oAsmDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewEnabled = True
oBOM.PartsOnlyViewEnabled = True
For Each doc As Document In oAsmDoc.AllReferencedDocuments
If doc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item(1)'Model data
Call ListItems(oBOMView.BOMRows, 0, doc)
End If
If doc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item(3)'Only Parts
Call ListItems(oBOMView.BOMRows, 0, doc)
End If
Next
Process.Start("Notepad.exe", oTextSave)
End Sub
Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, doc As Document)
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 <> doc.DisplayName Then
If Not oBOMRow.ChildRows Is Nothing Then
Call ListItems(oBOMRow.ChildRows, indent + 1,doc )
End If
Else
oDescrip = iProperties.Value(doc,"Project", "Description")
oPartNumber = iProperties.Value(doc, "Project", "Part Number")
oQty = oBOMRow.ItemQuantity
oData_X = oQty & " | " & rDocName & " | " & oDescrip & " | " & " | " & oPartNumber
oWrite_Data(oTextSave, oData_X)
End If
Next
End Sub
Sub oWrite_Data(oTextSave As String, oData As String)
oWrite = System.IO.File.AppendText(oTextSave)
oWrite.WriteLine(oData)
oWrite.Flush()
oWrite.Close
End Sub
Sub oWrite_HeaderLines(oTextSave As String, oHeaderLine As String)
oWrite = System.IO.File.AppendText(oTextSave)
oWrite.WriteLine(oHeaderLine)
oWrite.Flush()
oWrite.Close
End Sub
Sub oWrite_DashLine(oTextSave As String, oDashes As String)
oWrite = System.IO.File.AppendText(oTextSave)
oWrite.WriteLine(oDashes)
oWrite.Flush()
oWrite.Close
End Sub
Sub oDelete_ex_Notepad(oTextSave As String, iL_NO As String) 'To delete oTextSave if existing.
If System.IO.File.Exists(oTextSave) = True Then
System.IO.File.Delete(oTextSave)
MessageBox.Show("Existing (if any) File Deleted", iL_NO)
End If
End Sub
End Class
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