跳到主要内容

使用SOLIDWORKS API将表格内容读入数组

该示例演示了如何使用SOLIDWORKS API将选定表格(BOM、常规表格、切割清单表格等)的内容读入二维数组中。 labels: [数组, BOM, 读取, SOLIDWORKS API, 表格] redirect-from:

  • /2018/03/solidworks-api-model-read-table-content-into-array.html

该示例演示了如何使用SOLIDWORKS API将选定表格(BOM、常规表格、切割清单表格等)的内容读入二维数组中。

SOLIDWORKS API接口ITableAnnotation提供了对所有表格类型的数据访问。

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 "请选中表格"
End If
Else
MsgBox "请打开模型"
End If
End Sub