03-08-2022
11:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-08-2022
11:04 PM
How can I get the Item Quantity from a Structured or Model Data BOM View over all levels, Iterate Rows but how.
I know how to do a for each on all the BOM rows and compare the value with what I'm looking for.
But that level is not deep enough do I need to dive in the Child Rows I suppose.
I've tried that without success .
In other rules I've used iterate rows with succes.
I think my main issue is that I do not know/understand what to do too make the existing rule iterate.
It seems correct that you have to assign the BOM in another sub as the iterate function or sub?
Please help.
Function RecurseBOMRow(oBOMRows As BOMRowsEnumerator, Component As Document) As Integer
For Each oBOMRow In oBOMRows'.ChildRows
Dim oCompDef As ComponentDefinition
oCompDef = oBOMRow.ComponentDefinitions.Item(1)
If oCompDef.Document.FullFileName Like Component.FullFileName Then
QTY = oBOMRow.ItemQuantity()
' sw.WriteLine("Match: " & "oBOMRow.ItemQuantity: " & oBOMRow.ItemQuantity)
Return QTY
Exit Function
End If
'Call SetRowProps(oCompDef, oBOMRow.TotalQuantity)
If Not oBOMRow.ChildRows Is Nothing
Call RecurseBOMRow(oBOMRow.childrows, Component)
End If
Next
End FunctionFunction GetQTY_StructuredBOM(oDoc As Document, Component As Document)As Integer
Dim oAssyDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
'oBOM.PartsOnlyViewEnabled = True
'Dim oBOMView As BOMView = oBOM.BOMViews.Item(1) ' Model Data, see also Phantom Assemblies
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
'Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only")
'RecurseBOMRow(oBOMView.BOMRows, Component)
Dim oBOMRow As BOMRow
Dim oCompDef As ComponentDefinition
' sw.WriteLine("")
' sw.WriteLine("GetQTY_StructuredBOM")
' sw.WriteLine("Search BOMrows in doc: " & oDoc.DisplayName)
' sw.WriteLine("Search for Comp: " & Component.FullFileName)
' sw.WriteLine("BOMRows.Count: " & oBOMView.BOMRows.Count)
' sw.WriteLine("")
If Component.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
RecurseBOMRows(oBOMView.BOMRows, oDoc, Component)
End If
''''' For Each oBOMRow In oBOMView.BOMRows
''''' ' Set a reference to the primary ComponentDefinition of the row
''''' oCompDef = oBOMRow.ComponentDefinitions.Item(1)
'''''' Dim QTY_Of_Item As String
'''''' QTY_Of_Item = oBOMRow.ItemQuantity()
'''''' Dim Path_And_File_Name As String
'''''' Path_And_File_Name = oCompDef.Document.FullFileName
'''''' Dim BOM_Structure As String
'''''' BOM_Structure = oBOMRow.BOMStructure
'''''' List = List & vbCrLf & QTY_Of_Item & " - " & Path_And_File_Name & " - " & BOM_Structure
'''''' sw.WriteLine(List)
''''' If oCompDef.Document.FullFileName Like Component.FullFileName Then
''''' QTY = oBOMRow.ItemQuantity()
''''' sw.WriteLine("Match: " & "oBOMRow.ItemQuantity: " & oBOMRow.ItemQuantity)
''''' End If
'''''' If Not oBOMRow.ChildRows Is Nothing Then
'''''' Call GetQTY_StructuredBOM(oBOMRow.ChildRows, indent +2,"","")
'''''' End If
''''' Next
'MsgBox(List)
'sw.WriteLine("QTY AT END GetQTY_StructuredBOM : " & QTY & " " & oDoc.DisplayName)
Return QTY
End Function