Morning guys!
I`m working on the huge assembly with 10 configurations. I`m trying to activate every configuration and get the BOM, save it to Excel, go to next configuration and so on....
Below is the code: The problem I`m having is - that it takes ~12-15 seconds for the BOM to show up on the drawing and then disappear ....I`m wondering if there is another way or approach to do that? Can the model be hidden ?(Like in Excel where you can hide application and disable screen updating)
Sub InsertBOM()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetCurrentSheet.GetViews()(0) 'Set swView = swDraw.GetFirstView
'Inserting BOM Table
AnchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
bomType = SwConst.swBomType_e.swBomType_Indented
Configuration = "Default"
tableTemplate = "C:\TestVaul\BOM.sldbomtbt"
Set swBomAnn = swView.InsertBomTable4(True, 0, 0, AnchorType, bomType, Configuration, tableTemplate, False, swNumberingType_Detailed, True) ' true - ise anchor point
Set swBomFeat = swBomAnn.BomFeature
swBomFeat.KeepMissingItems = False
' selecting the table
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
If swFeat.GetTypeName = "BomFeat" Then
swFeat.Select (False)
Set swBomFeat = swFeat.GetSpecificFeature2
vTables = swBomFeat.GetTableAnnotations
Set swBomTable = vTables(0)
End If
Set swFeat = swFeat.GetNextFeature
Loop
' making sure Array is big enough to fit all data
ReDim BOMArray(0 To swBomTable.RowCount - 1, 0 To swBomTable.ColumnCount - 1)
' reading data from BOM on the drawing into 2d-Array
For i = 0 To swBomTable.RowCount - 1
For j = 0 To swBomTable.ColumnCount - 1
BOMArray(i, j) = swBomTable.DisplayedText(i, j)
Next j
Next i
'Work with BomFeature to get and set configurations
'All valid configurations are saved now in array Names()
Set swBomFeat = swBomTable.BomFeature
Names = swBomFeat.GetConfigurations(False, Visible)
Visible(0) = True
boolStatus = swBomFeat.SetConfigurations(True, Visible, Names)
' removing BOM from the model
swModel.EditDelete
SolidworksApi macros