I am using VBA code to automatically generate shop floor papers. As part of the process I create a Bill of Material Table to list all parts for an assembly.
I have one part used in two different sub assemblies of the main assembly. The problem now is that this parts with the same part number, description and configuration, is listed twice with qty=1 in each. I needs to be listed once with qty=2.
I can rectify that by setting the "Part configuration Grouping" to "Display all configurations of the same part as one items". It does not seems logical but it does work. The question now is: How do I set this in VBA code?
Regards
Jaco
Set "Bill of Materials" table properties with VBA code
-
- Posts: 51
- Joined: Wed Mar 01, 2023 6:55 pm
- x 36
- x 5
Set "Bill of Materials" table properties with VBA code
Try that instead of the failing line:
Dim swBomFeat As BomFeature
Set swBomFeat = swFeat.GetSpecificFeature2
Go to full postDim swBomFeat As BomFeature
Set swBomFeat = swFeat.GetSpecificFeature2
Re: Set "Bill of Materials" table properties with VBA code
PartConfigurationGrouping Property (IBomFeature)
-> https://help.solidworks.com/2024/englis ... uping.html
-> https://help.solidworks.com/2024/englis ... uping.html
-
- Posts: 51
- Joined: Wed Mar 01, 2023 6:55 pm
- x 36
- x 5
Re: Set "Bill of Materials" table properties with VBA code
Hi @RonE
Thanks for the message. I saw that before but I cannot get it to work. I have actually tried ChatGPT to help but I still cannot get it going. This is the code I got from ChatGPT:
Thanks for the message. I saw that before but I cannot get it to work. I have actually tried ChatGPT to help but I still cannot get it going. This is the code I got from ChatGPT:
I get a error message "Run-time error'13': Type mismatch" at the line "Set swBOMTable = swFeat.GetSpecificFeature2"
Sub SetPartConfigurationGrouping()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swAssembly As AssemblyDoc
Dim swBOMTable As BomTableAnnotation
Dim configOption As Integer
' Connect to SolidWorks
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Check if the active document is an assembly
If swModel.GetType <> swDocASSEMBLY Then
MsgBox "Please open an assembly document."
Exit Sub
End If
Set swAssembly = swModel
' Find the first BOM table in the assembly
Dim swFeat As Feature
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
If swFeat.GetTypeName2 = "BomFeat" Then
Set swBOMTable = swFeat.GetSpecificFeature2
Exit Do
End If
Set swFeat = swFeat.GetNextFeature
Loop
' Check if BOM table is found
If swBOMTable Is Nothing Then
MsgBox "No BOM table found in the assembly."
Exit Sub
End If
' Set the Part Configuration Grouping option
' 0 = Display all configurations of the same part as separate items
' 1 = Display all configurations with the same part number as one item
configOption = 1 ' Change to 0 if you want to display each configuration separately
swBOMTable.PartConfigurationGrouping = configOption
' Update the BOM to reflect the changes
swBOMTable.Update
MsgBox "Part Configuration Grouping option set successfully."
End Sub
Re: Set "Bill of Materials" table properties with VBA code
Try that instead of the failing line:
Dim swBomFeat As BomFeature
Set swBomFeat = swFeat.GetSpecificFeature2
Dim swBomFeat As BomFeature
Set swBomFeat = swFeat.GetSpecificFeature2
-
- Posts: 51
- Joined: Wed Mar 01, 2023 6:55 pm
- x 36
- x 5
Re: Set "Bill of Materials" table properties with VBA code
Hi @RonE
Thanks, it did the job. I am a self taught VBA programmer. Hopefully I will get better at it soon . I just need more reference material about the API
Regards
Jaco
Thanks, it did the job. I am a self taught VBA programmer. Hopefully I will get better at it soon . I just need more reference material about the API
Regards
Jaco