Is there a way to combine identical components in BOM table through MACRO? It seems that I cant find the right function for that and macro recorder do not record this step either.
Is there a way to combine identical components in BOM table through MACRO? It seems that I cant find the right function for that and macro recorder do not record this step either.
SPR 1030715-API required for option available in => Indented BOM => Combine Identical Components option.
Mithilesh Kapre Did they ever implement this request? Is this functionality now available in 2021? A macro to combine identical components would be a tremendous time saver.
I am running Solidworks 2021 SP01.
Thanks in advance!
I just checked the "Knowledge base" (in quotes because it hardly contains any knowledge) and this request is still open and not implemented.
Check this solution: Combine identical components command in SOLIDWORKS BOM table using SOLIDWORKS API
Wow - thanks for sharing. This is the first I've seen a SW command invoked using Windows API. Did some digging, and wanted to share your blog on this subject, if that's okay,Artem Taturevych.
Artem Taturevych wrote:
Check this solution: Combine identical components command in SOLIDWORKS BOM table using SOLIDWORKS API
Artem Taturevych I tried your macro you shared and it keeps throwing an error on
Set swFrame = swApp.Frame'
It says variable not set. I have done some programing in the past, but I'm not very familiar with VBA so I'm not sure what is wrong.
#If VBA7 Then
Private Declare PtrSafe Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
#Else
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
#End IfDim swApp As SldWorks.SldWorksSub main()Set swApp = Application.SldWorksDim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Dim swBomTable As SldWorks.TableAnnotation
Set swBomTable = swModel.SelectionManager.GetSelectedObject6(1, -1)
CombineIdenticalComponents swModel, swBomTable, 1, swBomTable.RowCount - 1
End SubSub CombineIdenticalComponents(model As SldWorks.ModelDoc2, table As SldWorks.BomTableAnnotation, startRowIndex As Integer, entRowIndex As Integer)
Dim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = model.SelectionManager
Dim swSelData As SldWorks.SelectData
Set swSelData = swSelMgr.CreateSelectData
Dim swTableAnnotation As SldWorks.TableAnnotation
Set swTableAnnotation = table
Dim swAnn As SldWorks.Annotation
Set swAnn = swTableAnnotation.GetAnnotation()
swSelData.SetCellRange startRowIndex, entRowIndex, 0, 0
swAnn.Select3 False, swSelData
RunCombineIdenticalComponentsCommand
End SubSub RunCombineIdenticalComponentsCommand()
Const WM_COMMAND As Long = &H111
Dim swFrame As SldWorks.Frame
Set swFrame = swApp.Frame
Const CMD_COMBINE_IDENTICAL_COMPONENTS As Long = 24378
SendMessage swFrame.GetHWnd(), WM_COMMAND, CMD_COMBINE_IDENTICAL_COMPONENTS, 0
End Sub
Any help is appreciated!
Thanks in advance!
You need to select the BOM table before running the macro.
Edit: I see the issue. You need to run the macro from the main sub. Just open for editing and run from main
I have now modified the macro to remove any ambiguity so you will not see this error anymore.
I finally got a chance to try it Artem Taturevych and works excellently! Thanks a lot Artem! This will save me a lot of time.
It appears to me this functionality is not included in the API.