4 Replies Latest reply on Jan 1, 2015 3:21 AM by Yong Ning

    How to set the name of the general table other than 'General Table1'?

    Arie Van Gelderen

      Hi all,

       

      I wrote a macro to insert a general table into a drawing. To insert the table I use the InsertTableAnnotation2 method. The macro works fine but I can't control the name of the table. My question is: is there a way to set the name of the general table other than 'General Table1' or 'General Table2' and so on?

       

      Hope someone can help me out here.

       

      Kind regards,

      Arie

        • Re: How to set the name of the general table other than 'General Table1'?
          Matt Martens

          Try this. When you insert the table it comes in as a ITableAnnotation object so convert it to an IAnnotation object using ITableAnnotation::GetAnnotation and use IAnnotation::SetName to change the name of it.

            • Re: How to set the name of the general table other than 'General Table1'?
              Arie Van Gelderen

              Hi Matt,

               

              Your solution was not what I was looking for. Your method sets/gets the annotation name and not the feature name. Debug.Print (tableName) returns 'DetailItem5349' instead of 'General Table1'.

               

              I found a solution myself though:

               

              Dim swApp               As SldWorks.SldWorks

              Dim swModelDoc          As SldWorks.ModelDoc2

              Dim swTable             As SldWorks.TableAnnotation

              Dim swGenTabFeature     As SldWorks.GeneralTableFeature

              Dim swFeature           As SldWorks.Feature

               

              Sub main()

                  Set swApp = Application.SldWorks

                  Set swModelDoc = swApp.ActiveDoc

               

                  Set swTable = swModelDoc.InsertTableAnnotation2(True, 0, 0, swBOMConfigurationAnchor_BottomRight, <PATHNAME>, 2, 4)

                  Set swGenTabFeature = swTable.GeneralTableFeature

                  Set swFeature = swGenTabFeature.GetFeature

                  Debug.Print (swFeature.Name)

                  swFeature.Name = "Tablename"

                 

              Thanks for the help anyway.

                • Re: How to set the name of the general table other than 'General Table1'?
                  Yong Ning

                  Private Sub ll()

                    Dim SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc, SwModel As ModelDoc2

                    Set SwApp = Application.SldWorks

                    Set SwDraw = SwApp.ActiveDoc

                    Dim GenTabFeat As GeneralTableFeature

                    Dim SwFeat As Feature, SwSubFeat As Feature, Ss

                    Dim SwGenTabFeat As GeneralTableFeature, SwGenTab As TableAnnotation

                    Dim SwSelMgr As SelectionMgr

                    With SwDraw 'SwModel

                       Set SwSelMgr = .SelectionManager

                       Set SwFeat = .FirstFeature

                       Do While Not SwFeat Is Nothing

                          'Debug.Print SwFeat.Name, SwFeat.GetTypeName

                          Set SwSubFeat = SwFeat.GetFirstSubFeature

                          Do While Not SwSubFeat Is Nothing

                           

                             If SwSubFeat.GetTypeName = "GeneralTableFeature" Then

                                Debug.Print "   ******" & SwSubFeat.Name, SwSubFeat.GetTypeName

                                SwSubFeat.Select True

                                Set SwGenTabFeat = SwSelMgr.GetSelectedObject6(1, 0)

                                ''

                                Ss = SwGenTabFeat.GetTableAnnotations

                                Set SwGenTab = Ss(0)

                              

                                Debug.Print SwGenTab.RowCount, SwGenTab.ColumnCount

                                Debug.Print

                                Debug.Print

                             End If

                           

                             Set SwSubFeat = SwSubFeat.GetNextSubFeature

                          Loop

                          Set SwFeat = SwFeat.GetNextFeature

                       Loop

                    End With  

                  End Sub

                  **************************************************

                   

                  Private Sub del20150101_1()

                     Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                        Set SwApp = Application.SldWorks

                        Set SwModel = SwApp.ActiveDoc

                        SwModel.ClearSelection

                     Dim SwDraw As DrawingDoc, SwView As View, Ss

                        Set SwDraw = SwModel

                     Dim SwSelMgr As SelectionMgr

                        Set SwSelMgr = SwDraw.SelectionManager

                    

                     Dim SwAnn As TableAnnotation, SwGenFeat As GeneralTableFeature, SwFeat As Feature

                    

                        Set SwFeat = SwModel.FeatureByName("Dn表")

                        Set SwGenFeat = SwFeat.GetSpecificFeature2

                       

                        SwFeat.Select True

                        Set SwGenFeat = SwSelMgr.GetSelectedObject6(1, 0)

                        Ss = SwGenFeat.GetTableAnnotations

                        ''

                        Debug.Print SwGenFeat.GetFeature.Name

                        ''

                        Set SwAnn = Ss(0)

                       

                        With SwAnn        

                           '.InsertColumn 2, 0, "aa"

                           .DeleteColumn 1

                           .DeleteRow 0       

                        End With

                        'Stop

                  End Sub