Hey everyone,
I'm looking for a way to get the pictured BOM with correct Quantities.
The BOM should only show TopLevel components.
If a component is an Assembly, it should get a separate TopLevel BOM underneath.
My example: "0C" consists of 5 subassemblies. The "0C_Chassis" BOM follows underneath.
My problem:
The way i do it (two For-loops after each other going through all components), it does not merge identical components.
Private Sub Fill_Worksheet(compAssy As AssemblyDoc)
Dim Comp As Variant
Dim Comps As Variant
Dim CompDoc As ModelDoc2
Comps = compAssy.GetComponents(True)For Each Comp In Comps
If Comp.GetSuppression <> 0 Then ' exclude suppressed parts
Set CompDoc = Comp.GetModelDoc
'Debug.Print "Type: " & CompDoc.GetType
xlWS.Cells(rowOffset, 2).Value = CompDoc.GetTitle
rowOffset = rowOffset + 1
End If
Next
For Each Comp In Comps
If Comp.GetSuppression <> 0 Then ' exclude suppressed parts
Set CompDoc = Comp.GetModelDoc
If CompDoc.GetType = 2 Then
xlWS.Cells(rowOffset, 1).Value = CompDoc.GetTitle
Call Fill_Worksheet(CompDoc)
End If
End If
Next
End Sub
Question:
A) Is there a simple way to get the amount of a component?
I usually get the components of an assembly via:
Set swBOMTable = CompDoc.Extension.InsertBomTable3(BOMTemplate, 0, 0, BOMType, ConfigName, True, BOMNoType, True)
Set swTable = swBOMTable
This way you also get the amounts and no duplicate lines.
Problem: you cannot call "CompDoc.Extension.InsertBomTable3" on a child component.
It throws a "serious error" and leads to Solidworks crashing ungraceful..
Hence this option would only work for the first TopLevel BOM but not for the SubAssy BOMs.
Question:
B) is there a way to create a BOM for a Subassy that is not opened and active or do I need to go the way of option A?
Looking forward to you suggestions.
Best,
Tobi
Alright, thanks! That was easier than I expected.
If someone in the future looks for something similar, here the solution: