Hi thanks for the help,
The comments are noted, I think once I'm sorted, I'll go to pulling the information from the drawing as recommended
For reference my setup here is always - one General assembly per project, I have my own content center set up, but I don't have any libraries as such. All parts only exist in this project for this build, If I want to use a part or assembly for another project, I just copy the part into that project file. This is something I do very rarely. I work on my own as a contractor so right now there's no need to worry about other people. But all the same working from the drawing seems safer/smarter and P1 of the drawing is always the general assembly, so I'd likely pull my information from there.
Right now, though I would also like to be able to tell the qty of assemblies. I've modified the code that Dalton wrote to pick up on assemblies as well as parts and changed the BOM to structured, however it's having the obvious effect of setting the quantities to what's shown in the structured view. The goal here would be that the rule will hunt through the whole assembly to give me the total qty of a part assembly required. E.g if I use an assembly on the third layer and again on the second layer, I would like it to tell me I need to make two of these assemblies.
This is how I've modified the code.
The intention is that
1) I have changed the Bom to be structured and not First level only
2) The first run sets the "TOTAL QTY" = 0
3) The intention of the second run is that when I go through each row it would add anything already in that property to the what's showing in the item qty at that level. i.e. I threw 5 random parts into the top-level assembly, and then 3 random parts into a sub assembly in placed this in the main assembly. When it hits the row of parts the second time it would add the new qty to the existing qty to give the total qty. This currently isn't working but I'm unsure if this is because of the structured parts list not being correct or my logic to add the values.
Any assistance would be appreciated
Kind Regards
Roydon Mackay
Dim oAdoc As AssemblyDocument = ThisDoc.Document
Dim oBOM As BOM = oAdoc.ComponentDefinition.BOM
'oBOM.PartsOnlyViewEnabled = True
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
'oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
Dim oRow As BOMRow
For Each oRow In oBOMView.BOMRows
Dim oDoc As Document
oDoc = ThisApplication.Documents.Open(oRow.ComponentDefinitions(1).Document.FullFileName, False)
oDoc.PropertySets.Item(4).Item("TOTAL QTY").Value = 0
Next
For Each oRow In oBOMView.BOMRows
If oRow.ComponentDefinitions.Count > 1
MessageBox.Show("Duplicate Part #'s")
End If
Dim oDoc As Document
oDoc = ThisApplication.Documents.Open(oRow.ComponentDefinitions(1).Document.FullFileName, False)
'Catch
'Dim oDoc As AssemblyDocument
'oDoc = ThisApplication.Documents.Open(oRow.ComponentDefinitions(1).Document.FullFileName, False)
'End Try
'custom iProperty
Try
oDoc.PropertySets.Item(4).Item("TOTAL QTY").Value = oRow.ItemQuantity + oDoc.PropertySets.Item(4).Item("TOTAL QTY").Value
Catch
'oDoc.PropertySets.Item(4).Add(oRow.ItemQuantity, "TOTAL QTY")
End Try
'oDoc.Close (True)
Next