-
Re: Adding a row at the end of a BOM table - API
Amen Allah Jlili Dec 18, 2015 2:55 PM (in response to Dennis Hvam)Try this short snippet. It should work, I've tested it.
Pre-condition: BOM is selectedSub main() Dim swapp As SldWorks.SldWorks Dim swmodel As ModelDoc2 Dim swselectionmanager As SelectionMgr Dim swannotationtable As TableAnnotation Dim result As Boolean Set swapp = Application.SldWorks Set swmodel = swapp.ActiveDoc Set swselectionmanager = swmodel.SelectionManager Set swannotationtable = swselectionmanager.GetSelectedObject6(1, -1) result = swannotationtable.InsertRow(4, swannotationtable.RowCount) Dim rowletter As String rowletter = ChrW(64 + swannotationtable.ColumnCount) swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 1) = _ "=SUM(" & rowletter & "1:" & rowletter & swannotationtable.RowCount - 1 & ")" End Sub
-
Re: Adding a row at the end of a BOM table - API
Dennis Hvam Dec 21, 2015 7:44 AM (in response to Amen Allah Jlili)Hello Amen,
This works like a charm!
Is there any way to get it to work without preselecting the BOM, or have a code that selects the BOM, the reason is that all the Drawings is run through DriveWorks, and I don't actually interact with the drawings.
The BOM's can have a specific name if that is required
-
Re: Adding a row at the end of a BOM table - API
Amen Allah Jlili Dec 21, 2015 8:27 AM (in response to Dennis Hvam)Alright big boy, here's what you asked for.
Notes: Instead of using the selection manager, the snippet below uses the feature manager to get the bom feature and add the sum row. Make sure to change the BomFeatureName string variable to the BOM feature name in your feature manager. Please note that it's case-sensitive. The snippet will yield an error if a bom with the specified name is not found.
Sub main() On Error GoTo handler: Dim BomFeatureName As String: BomFeatureName = "Bill of Materials1" Dim swapp As SldWorks.SldWorks Dim swmodel As ModelDoc2 Dim swannotationtable As TableAnnotation Dim result As Boolean Dim featuremanager As featuremanager Dim feature As feature Dim vfeature As Variant Set swapp = Application.SldWorks Set swmodel = swapp.ActiveDoc Set featuremanager = swmodel.featuremanager vfeatures = featuremanager.GetFeatures(True) For i = 0 To UBound(vfeatures) Set feature = vfeatures(i) If feature.Name = BomFeatureName Then Dim bomfeature As bomfeature Set bomfeature = feature.GetSpecificFeature2 Dim bomtableannotation As bomtableannotation Set bomtableannotation = bomfeature.GetTableAnnotations(0) Set swannotationtable = bomtableannotation Exit For End If Next i result = swannotationtable.InsertRow(4, swannotationtable.RowCount) Dim rowletter As String rowletter = ChrW(64 + swannotationtable.ColumnCount) swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 1) = _ "=SUM(" & rowletter & "1:" & rowletter & swannotationtable.RowCount - 1 & ")" Exit Sub handler: swapp.SendMsgToUser ("Cannot find BOM with the name: " + BomFeatureName) End Sub
-
Re: Adding a row at the end of a BOM table - API
Dennis Hvam Dec 21, 2015 9:00 AM (in response to Amen Allah Jlili)Hello again Amen,
You are fast AND and spot on!
Thank you so much for this, its a huge help for me!
-
-
-