- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
I use a copied piece of recursive code in my iLogic Rule and I have some issues.
I already 'fixed' it for IPT's but I still get incorrect numbers for assemblies (in large assemblies)
First example of code is located in Main()
Now, I already found out earlier that the part quantities didn't behave as intended so I 'fixed' it by just reading the parts only quantities.
However. It's not right and I need to fix it for real this time.
BUT! I don't quite know how it works. Can anyone help me out in understanding recursive code like the one below?
I'm curious about the RecurseBOMRow() and SetRowProps()
Correct me if I'm wrong:
RecurseBOMRow travels through the first parts of the assembly (if it has no additional rows)
If it has more rows inside the bom it will call itself
SetRowProps Sets the QTY integer which then is passed to the oTotalDict (VBA Dictionary)
How does SetRowProps set the amounts though?
Dim oBOMRow As BOMRow Dim oCompDef As ComponentDefinition For Each oBOMRow In oBOMView.BOMRows oCompDef = oBOMRow.ComponentDefinitions.Item(1) Call SetRowProps(oCompDef, oBOMRow.TotalQuantity, oTotalDict, xProduce) If Not oBOMRow.ChildRows Is Nothing Call RecurseBOMRow(oBOMRow, oTotalDict, xProduce) End If Next Trace.WriteLine("Making Partsonly QTY's (NOT INTENDED)") Try oBOMView = oBOM.BOMViews.Item("Parts Only") Catch MessageBox.Show("BOM not accessible. PARTS ONLY DISABLED?", "IAM Bulk Drawing Tool") vaultaddin.Activate Exit Sub End Try For Each oBOMRow In oBOMView.BOMRows oCompDef = oBOMRow.ComponentDefinitions.Item(1) Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName Dim CompFileNameOnly As String Dim index As Integer = CompFullDocumentName.LastIndexOf("\") CompFileNameOnly = CompFullDocumentName.Substring(index + 1) QTY = oBOMRow.TotalQuantity * xProduce oTotalDict(CompFullDocumentName) = QTY Next
Sub RecurseBOMRow(oBOMRow As BOMRow, oTotalDict As Dictionary(Of String, Integer), xProduce As Integer) For Each oBOMRow In oBOMRow.ChildRows Dim oCompDef As ComponentDefinition oCompDef = oBOMRow.ComponentDefinitions.Item(1) Call SetRowProps(oCompDef, oBOMRow.TotalQuantity, oTotalDict, xProduce) If Not oBOMRow.ChildRows Is Nothing Call RecurseBOMRow(oBOMRow, oTotalDict, xProduce) End If Next End Sub Sub SetRowProps(oCompDef As ComponentDefinition, QTY As Integer, oTotalDict As Dictionary(Of String, Integer), xProduce As Integer) Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName Dim CompFileNameOnly As String Dim index As Integer = CompFullDocumentName.LastIndexOf("\") CompFileNameOnly = CompFullDocumentName.Substring(index + 1) QTY = QTY * xProduce oTotalDict(CompFullDocumentName) = QTY End Sub
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
___________________________Solved! Go to Solution.