In our BOM's we have frame generated parts that use "Part Number" to show they are the same, because they are determined by size not just the item description.
I currently use a rule that counts all the components in an assembly and puts that into a BOM field. However it only puts the value into one of them the rest are left blank.
How can I get the value to populate the other items as well? The only way I have seen is by them having the same file name but because these all have different file names I need to do it by part number.
Part number example: ANGLE 3" X 3" X 3/8" X 40' A36 C.S. X 49.742 - 002-01
Here is the rule another user posted that I modified and am currently using.
Thanks,
Class ThisRule Dim rDoc As Document, oDoc As Document Dim oQty As Integer Sub Main() On Error Resume Next Dim oAssem As AssemblyDocument = ThisDoc.Document Dim oBOM As BOM = oAssem.ComponentDefinition.BOM oBOM.StructuredViewFirstLevelOnly = False oBOM.StructuredViewEnabled = True oBOM.PartsOnlyViewEnabled = True oBOM.SetPartNumberMergeSettings(True, ) For Each oDoc In oAssem.AllReferencedDocuments oQty = 0 If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) Next End Sub Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document) For Each oBOMRow As BOMRow In Rows rDoc = oBOMRow.ComponentDefinitions.Item(1).Document If rDoc IsNot oDoc Then If Not oBOMRow.ChildRows Is Nothing Then Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc) End If Else oQty = oQty + oBOMRow.ItemQuantity iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty End If Next End Sub End Class
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
See my added code below.
Class ThisRule Dim rDoc As Document, oDoc As Document Dim oQty As Integer Sub Main() On Error Resume Next Dim oAssem As AssemblyDocument = ThisDoc.Document Dim oBOM As BOM = oAssem.ComponentDefinition.BOM oBOM.StructuredViewFirstLevelOnly = False oBOM.StructuredViewEnabled = True oBOM.PartsOnlyViewEnabled = True oBOM.SetPartNumberMergeSettings(True, ) For Each oDoc In oAssem.AllReferencedDocuments oQty = 0 If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) '===================================================================================== '==============================ADDED CODE============================================= '===================================================================================== ' At this point in your rule, you need to iterate through all referenced docs again, and apply ' the quantity of this doc to all docs with the same Part Number. Something like this: Dim oDocPN As String = iProperties.Value(oDoc.DisplayName, "Project", "Part Number") If oDocPN <> "" Then For Each oDoc2 As Document In oAssem.AllReferencedDocuments If oDoc2 Is oDoc Then Continue For ' Skip current document Dim oDoc2PN As String = iProperties.Value(oDoc2.DisplayName, "Project", "Part Number") If oDoc2PN = oDocPN Then ' This doc has the same PN as the current document. Set its quantity to the same value. iProperties.Value(oDoc2.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty End If Next End If '===================================================================================== '==============================END ADDED CODE========================================= '===================================================================================== Next End Sub Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document) For Each oBOMRow As BOMRow In Rows rDoc = oBOMRow.ComponentDefinitions.Item(1).Document If rDoc IsNot oDoc Then If Not oBOMRow.ChildRows Is Nothing Then Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc) End If Else oQty = oQty + oBOMRow.ItemQuantity iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty End If Next End Sub End Class
I made some modifications and added the clean up after the initial parameter changes.
Class ThisRule Dim rDoc As Document, oDoc As Document Dim oQty As Integer Sub Main() On Error Resume Next Dim oAssem As AssemblyDocument = ThisDoc.Document Dim oBOM As BOM = oAssem.ComponentDefinition.BOM oBOM.StructuredViewFirstLevelOnly = False oBOM.StructuredViewEnabled = True oBOM.PartsOnlyViewEnabled = True oBOM.SetPartNumberMergeSettings(False, ) For Each oDoc In oAssem.AllReferencedDocuments oQty = 0 If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) Next Call Sub() CopyPaste End Sub Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document) For Each oBOMRow As BOMRow In Rows rDoc = oBOMRow.ComponentDefinitions.Item(1).Document If rDoc IsNot oDoc Then If Not oBOMRow.ChildRows Is Nothing Then Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc) End If Else oQty = oQty + oBOMRow.ItemQuantity iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty End If Next End Sub Sub CopyPaste On Error Resume Next Dim rDoc As Document, oDoc As Document Dim oQty As Integer Dim oAssem As AssemblyDocument = ThisDoc.Document Dim oBOM As BOM = oAssem.ComponentDefinition.BOM Dim oBOMRow As BOMRow For Each oDoc In oAssem.AllReferencedDocuments If iProperties.Value(rDoc.DisplayName, "Summary", "Title") <> " " Then rDoc = oBOMRow.ComponentDefinitions.Item(1).Document End If If iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "" Then oDoc2 = oBOMRow.ComponentDefinitions.Item(1).Document End If Next For Each oDoc In oAssem.AllReferencedDocuments iProperties.Value(oDoc2.DisplayName, "Summary", "Title") = iProperties.Value(rDoc.DisplayName, "Summary", "Title") Next End Sub End Class
I had a quick look and I think we just needed to add a For/Each to look through the BOMRow references(comp. defs), when there are more than one (which is the case when the row has merged PNs) ...
See if this works, and be on the look out of anything I might have broke (I didn't spend much time testing, etc)
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Class ThisRule Dim rDoc As Document, oDoc As Document Dim oQty As Integer Sub Main() On Error Resume Next Dim oAssem As AssemblyDocument = ThisDoc.Document Dim oBOM As BOM = oAssem.ComponentDefinition.BOM oBOM.StructuredViewFirstLevelOnly = False oBOM.StructuredViewEnabled = True oBOM.PartsOnlyViewEnabled = True oBOM.SetPartNumberMergeSettings(True, ) For Each oDoc In oAssem.AllReferencedDocuments oQty = 0 If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) 'assembly If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) 'part Next End Sub Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document) For Each oBOMRow As BOMRow In Rows rDoc = oBOMRow.ComponentDefinitions.Item(1).Document Trace.WriteLine(rDoc.fullfilename, "iLogic") 'debug If rDoc IsNot oDoc Then If Not oBOMRow.ChildRows Is Nothing Then Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc) End If Else oQty = oQty + oBOMRow.ItemQuantity i=1 For Each kDoc in oBOMRow.ComponentDefinitions rDoc = oBOMRow.ComponentDefinitions.Item(i).Document iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty i=i+1 Next End If Next End Sub End Class
Inventor Forum links: Inventor iLogic , API and Customization Forum | Inventor Ideas Forum | General Inventor Forum
Thanks again for the help.
It seems to be working except for the occasional anomaly. For some reason it doesn't change the property on a few of the BOM items. They aren't library parts and don't have any write protections so I am confused as to why they aren't updating.
They are old Frame generated parts. All of them are of the same part but different lengths. Some get updated but a few don't. Perhaps it's because these parts are several years old?
Hi @Brian.Price ,
If you open one of those frame parts and save, do you get any notices about the part needing to be migrated to the current version of Inventor, etc? If so, does saving it then allow it to be updated with the ilogic rule?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Inventor Forum links: Inventor iLogic , API and Customization Forum | Inventor Ideas Forum | General Inventor Forum
Well this got weird.
The parts have been migrated to the newest edition of Inventor.
When I ran the rule without the error skip it gives me an error that says it can't find the file
None of the files are named the same as what is in the error. I also removed the edited part of the name file so it was the same as the error, and it still didn't find the file.
Hi @Brian.Price .
Okay that makes sense.... it has to do with the fact that the file is in a subassembly (frame sub assembly in this case)... so as written its looking at the top level for it and not finding it, I'll look at this in a bit and provide and update (I'm in the middle of something at the moment).
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Inventor Forum links: Inventor iLogic , API and Customization Forum | Inventor Ideas Forum | General Inventor Forum
Hi @Brian.Price
Give this a try and report back if it doesn't work... the issue was partially what I mentioned earlier, but partially the use of "displayname", this version just uses the API call to look at the document file to set the iproperty (rather than trying to set the iproperty via the occurrence, which is how the ilogic call does it).
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Class ThisRule Dim rDoc As Document, oDoc As Document Dim oQty As Integer Sub Main() On Error Resume Next Dim oAssem As AssemblyDocument = ThisDoc.Document Dim oBOM As BOM = oAssem.ComponentDefinition.BOM oBOM.StructuredViewFirstLevelOnly = False oBOM.StructuredViewEnabled = True oBOM.PartsOnlyViewEnabled = True oBOM.SetPartNumberMergeSettings(True, ) For Each oDoc In oAssem.AllReferencedDocuments oQty = 0 If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) 'assembly If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) 'part Next End Sub Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document) For Each oBOMRow As BOMRow In Rows rDoc = oBOMRow.ComponentDefinitions.Item(1).Document If rDoc IsNot oDoc Then If Not oBOMRow.ChildRows Is Nothing Then Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc) End If Else oQty = oQty + oBOMRow.ItemQuantity i=1 For Each kDoc In oBOMRow.ComponentDefinitions rDoc = oBOMRow.ComponentDefinitions.Item(i).Document rDoc.PropertySets("Summary Information").Item("Title").value _ = "MASTER BOM QTY " & oQty i=i+1 Next End If Next End Sub End Class
Inventor Forum links: Inventor iLogic , API and Customization Forum | Inventor Ideas Forum | General Inventor Forum
Curtis,
Thanx a lot for this code.
It's exactly what I need.
I just changed the targeted iProperty and it's perfect!
Took 2 full days to work through examples in this forum to try to adjust them to my needs, but nothing worked.
The problem is, all the codes samples I found don't handle multiple c/c parts w/the same Mark#, so the total qty's were wrong for many of the parts. I'm just not smart enough in this stuff (yet) to figure it out. But then today I found your code.
Many thanx!
Can't find what you're looking for? Ask the community or share your knowledge.