2 Replies Latest reply on Jul 6, 2018 1:16 AM by Prabaharan Pichaiyan

    Insert table API Issue.

    Prabaharan Pichaiyan

      Hi,

       

      I try to create table using the SWx sample macro(Attached).

      Its working fine for the first run. if I delete the created table and rerun the macro again, its getting a error

      May I know what was the issue with these codes?

       

      Thanks

        • Re: Insert table API Issue.
          Fifi Riri

          Hello,

          Each time you insert a table with InsertTableAnnotation2 it increment its name

          So you get the error when you try to select it with SelectID2("General Table1"...

           

          Try this:

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swDrawing As SldWorks.DrawingDoc

          Dim swTableAnnotation As SldWorks.TableAnnotation

          Dim swGeneralTableFeature As SldWorks.GeneralTableFeature

          Dim swSelectionMgr As SldWorks.SelectionMgr

          Dim swModelDocExt As SldWorks.ModelDocExtension

          Dim swFeature As SldWorks.Feature

          Dim nbrTableAnnotations As Long

          Dim tableAnnotations As Variant

          Dim i As Long

          Dim anchorAttached As Boolean

          Dim anchorType As Long

          Dim nbrColumns As Long

          Dim nbrRows As Long

          Sub main()

              Set swApp = Application.SldWorks

              'Open drawing document

              Set swModel = swApp.ActiveDoc

              'Insert table annotation

              Set swDrawing = swModel

              Set swTableAnnotation = swDrawing.InsertTableAnnotation2(False, 2.75123456559767E-02, 0.132124518483965, 1, "", 2, 2)

           

              If Not swTableAnnotation Is Nothing Then

                 swTableAnnotation.BorderLineWeight = 0

                 swTableAnnotation.GridLineWeight = 0

              End If

           

              Set swGeneralTableFeature = swTableAnnotation.GeneralTableFeature

              Set swFeature = swGeneralTableFeature.GetFeature

              Debug.Print "General table feature name: " & swFeature.Name

            

              'Get general table feature's annotation data

              nbrTableAnnotations = swGeneralTableFeature.GetTableAnnotationCount

              Debug.Print "Number of annotations = " & nbrTableAnnotations

              tableAnnotations = swGeneralTableFeature.GetTableAnnotations

              For i = 0 To (nbrTableAnnotations - 1)

                  Set swTableAnnotation = tableAnnotations(i)

                  anchorAttached = swTableAnnotation.Anchored

                  Debug.Print "Table anchored        = " & anchorAttached

                  anchorType = swTableAnnotation.anchorType

                  Debug.Print "Anchor type           = " & anchorType

                  nbrColumns = swTableAnnotation.ColumnCount

                  Debug.Print "Number of columns     = " & nbrColumns

                  nbrRows = swTableAnnotation.RowCount

                  Debug.Print "Number of rows        = " & nbrRows

              Next i

          End Sub