Bob M. answered 12/30/20
Expert Mechanical Design Engineer/Manager
- Create a New Macro
- Use the New Macro button in the Macro Toolbar (or select Tools > Macro > New)
- Ensure that the references in SOLIDWORKS Visual Basic Editor (VBA) are correct with your SOLIDWORKS Version
- Copy the code below and change the Highlighted Orange text to match your environment:
- Save the code
- Run
Preconditions: Ensure you are running the code below on a DRAWING containing a MODEL, which contains multiple configurations.
Results: In the OUTPUT_FOLDER of your choice, you should see the Drawing files for EACH configuration with an updated BOM
CHECK THE MACRO ON A SECOND PART OF THE ANSWER
Bob M.
Const OUTPUT_FOLDER = "C:\Out\" Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swDraw As SldWorks.DrawingDoc Dim swRefModel As SldWorks.ModelDoc2 Sub main() Dim i As Integer Dim vConfs As Variant Dim swView As SldWorks.View Dim confName As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swDraw = swModel Set swView = swDraw.GetFirstView().GetNextView Set swRefModel = swView.ReferencedDocument vConfs = swRefModel.GetConfigurationNames For i = 0 To UBound(vConfs) confName = vConfs(i) ProcessViews confName swModel.ForceRebuild3 False boolstatus = swModel.Extension.SaveAs(OUTPUT_FOLDER + confName + ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Copy, Nothing, 0, 0) Next i MsgBox "Completed" Set swApp = Nothing Set swModel = Nothing Set swDraw = Nothing Set swRefModel = Nothing End Sub Sub ProcessViews(confName As String) Dim i As Integer Dim vSheets As Variant Dim j As Integer Dim vViews As Variant Dim swFeat As SldWorks.Feature Dim swView As SldWorks.View vSheets = swDraw.GetViews For i = 0 To UBound(vSheets) vViews = vSheets(i) For j = 0 To UBound(vViews) Set swView = vViews(j) swView.ReferencedConfiguration = confName Next j 'delete BOM Set swFeat = swDraw.FirstFeature Debug.Print swFeat.Name + " - " + swFeat.GetTypeName While Not swFeat Is Nothing Debug.Print swFeat.Name + " - " + swFeat.GetTypeName If "BomFeat" = swFeat.GetTypeName Then swFeat.Select2 False, -1 swDraw.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed End If Set swFeat = swFeat.GetNextFeature Wend boolstatus = swModel.Extension.SelectByID2(swView.Name, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0) AnchorType = swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft BomType = swBomType_e.swBomType_PartsOnly Configuration = confName TableTemplate = "" ' Insert BOM table Set swBomAnn = swView.InsertBomTable2(True, 0.4, 0.3, AnchorType, BomType, Configuration, TableTemplate) swModel.ClearSelection2 True ' Update FeatureManager design tree swDraw.ForceRebuild Next i Set swFeat = Nothing Set swView = Nothing End Sub12/30/20