Hide Table of Contents

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



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Table Cell Text Example (VB.NET)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2012 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.