Skip to main content

Read table content into array using SOLIDWORKS API

This example demonstrates how to read the content of the selected table (Bill Of Materials, General Table, Cut-List Table etc.) into the 2-dimensional array using SOLIDWORKS API.

ITableAnnotation SOLIDWORKS API interface provides an access to the data of all table types.

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swTableAnnotation As SldWorks.TableAnnotation

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

If Not swModel Is Nothing Then

Set swSelMgr = swModel.SelectionManager

Dim tableData() As String

Set swTableAnnotation = swSelMgr.GetSelectedObject6(1, -1)

If Not swTableAnnotation Is Nothing Then

ReDim tableData(swTableAnnotation.RowCount - 1, swTableAnnotation.ColumnCount - 1)

Dim i As Integer
Dim j As Integer

For i = 0 To swTableAnnotation.RowCount - 1

For j = 0 To swTableAnnotation.ColumnCount - 1
tableData(i, j) = swTableAnnotation.Text(i, j)
Next

Next
Else
MsgBox "Please select table"
End If
Else
MsgBox "Please open model"
End If
End Sub