Get Table Cell Text Example (VB.NET)
This example shows how to get all of the cell text
from a BOM table using the SolidWorks Document Manager API.
'---------------------------------------------------------------------------
' Preconditions:
' 1. Read the SolidWorks Document Manager API Help
' Getting
Started topic and ensure that the
' required DLLs are registered.
' 2. Ensure that the latest SolidWorks.Interop.swdocumentmgr.dll
'
interop assembly is loaded in the project
' (right-click
on the project in Project Explorer, click
' Add Reference, select
the interop assembly from the .NET
' tab or browse for the DLL in <SolidWorks_install_dir>/api/redist
' directory).
' 3. In SolidWorks, create a part document with a BOM
table.
' 4. Save the part and close it.
' 5. Substitute your license key for "your_license_key"
in the code.
' 6. Substitute the new file name for sFile in the code.
'
' Postconditions: The Immediate Window displays the BOM
' table row and
column count and all of the table's cell
' text in row order.
'--------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports SolidWorks.Interop.swdocumentmgr
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
Dim
classfac As SwDMClassFactory
Dim
tapp As SwDMApplication
Dim
swDoc As SwDMDocument13
Dim
swTable As SwDMTable3
Dim
e As SwDmDocumentOpenError
Dim
sFile As String
Dim
vTables As Object
Dim
vTabArr As Object
Dim
err As SwDmTableError
Dim
row As Long, col As Long
Dim
i As Long, j As Long
Sub
Main()
classfac
= CreateObject("SwDocumentMgr.SwDMClassFactory")
tapp
= classfac.GetApplication("your_license_key")
'license needed please do not distribute this
sFile =
"C:\temp\Part1.SLDPRT"
'get
the SW document file
swDoc = tapp.GetDocument(sFile, SwDmDocumentType.swDmDocumentPart,
False, e)
'Set
swDoc = tapp.GetDocument(sFile, SwDmDocumentType.swDmDocumentAssembly,
False, e)
'Set
swDoc = tapp.GetDocument(sFile, SwDmDocumentType.swDmDocumentDrawing,
False, e)
Debug.Print("Doc
Version is " & swDoc.GetVersion)
Debug.Print("Doc
name is " & swDoc.FullName)
vTables
= swDoc.GetTableNames(SwDmTableType.swDmTableTypeBOM)
If
Not IsNothing(vTables) Then
swTable
= swDoc.GetTable(vTables(0))
If
Not swTable Is Nothing Then
Debug.Print("Table
retrieved is " & vTables(0))
vTabArr
= swTable.GetTableCellText(err,
row, col)
Debug.Print("Row
count is " & row)
Debug.Print("Column
count is " & col)
Debug.Print("Table
cell text:")
For
j = 0 To UBound(vTabArr)
Debug.Print("
"
& vTabArr(j))
Next
End
If
End
If
swDoc.CloseDoc()
End
Sub
Public
swApp As SldWorks
End Class