2 Replies Latest reply on Oct 18, 2018 11:39 AM by Gennadiy Tsybikov

    How to use API to get table information?

    ZhongYu Hao

      Hello,everyone.

      I want use SW API to get table information.

      The code I fined was:

      GetTableAnnotations

      But ,how do i use it.? Because I need get General table and hole table information.

        • Re: How to use API to get table information?
          Gennadiy Tsybikov

          See example below on how to get any table information from Drawing using IView::GetTableAnnotations Method

           

          Option Explicit

           

          'Preconditions

          '1. Open Drawing Model

          '2. Results will be printed in Immediate Window

           

          Sub Main()

           

              Dim SwApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swDrawDoc As SldWorks.DrawingDoc

              Dim swAnnot As SldWorks.Annotation

              Dim SwView As SldWorks.View

              Dim vViews As Variant

              Dim vTableAnnots As Variant

              Dim swTableAnnot As SldWorks.TableAnnotation

              Dim intTableAnnotCount As Integer

              Dim i As Integer

              Dim intCol As Integer

              Dim intRow As Integer

           

           

              Set SwApp = Application.SldWorks

              Set swModel = SwApp.ActiveDoc

            

              If swModel.GetType = swDocumentTypes_e.swDocASSEMBLY Or swModel.GetType = swDocumentTypes_e.swDocPART Then

                  MsgBox "Please open drawing and try again."

                  Exit Sub

              End If

            

              Set swDrawDoc = swModel

            

                  Set SwView = swDrawDoc.GetFirstView

                  vTableAnnots = SwView.GetTableAnnotations

                  intTableAnnotCount = SwView.GetTableAnnotationCount

           

           

                  If intTableAnnotCount > 0 Then

                      For i = 0 To UBound(vTableAnnots)

                          Set swTableAnnot = vTableAnnots(i)

                        

                          'Use table types below depending on what table you want to get information from:

                          'swTableAnnotation_HoleChart swTableAnnotation_BillOfMaterials etc...

                          If swTableAnnot.Type = swTableAnnotationType_e.swTableAnnotation_General Then

                              For intCol = 0 To swTableAnnot.ColumnCount - 1

                                  For intRow = 0 To swTableAnnot.RowCount

                                      Debug.Print swTableAnnot.Text(intRow, intCol)

                                  Next intRow

                              Next intCol

                        

                          End If

                        

                      Next i

                    

                  End If

                

          End Sub