2 Replies Latest reply on Jun 3, 2016 8:26 AM by Yong Ning

    Why can only delete a General Table

    Yong Ning

      SwSubFeat.Select False

      editdelete → can be delete One General table

      0.jpg

       

      SwSubFeat.Select True

      editdelete  →  don't delete the General table

       

      1.jpg

       

      Select many Feature of GeneralTableFeature, but don't delete General table.

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

      follow code

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

      Sub main()

       

          Dim SwApp                                   As SldWorks.SldWorks

          Dim SwModel                                 As SldWorks.ModelDoc2

          Dim SwFeat                                  As SldWorks.Feature

          Dim SwSubFeat                               As SldWorks.Feature

          Dim sFeatType                               As String

          Set SwApp = Application.SldWorks

          Set SwModel = SwApp.ActiveDoc

          'Debug.Print "File = " & SwModel.GetPathName

          Set SwFeat = SwModel.FirstFeature

          Do While Not SwFeat Is Nothing

              'Debug.Print SwFeat.Name, SwFeat.GetTypeName

              Set SwSubFeat = SwFeat.GetFirstSubFeature

              Do While Not SwSubFeat Is Nothing

                  'Debug.Print SwSubFeat.Name, SwSubFeat.GetTypeName

                  If SwSubFeat.GetTypeName = "GeneralTableFeature" Then

                     Debug.Print SwSubFeat.Name

                     SwSubFeat.Select False

                     SwModel.EditDelete

                  End If

                  Set SwSubFeat = SwSubFeat.GetNextSubFeature

              Loop

              Set SwFeat = SwFeat.GetNextFeature

          Loop

      End Sub

      '-----------------------------------------------

       

      Hope , Select Many General Table → delete many general table

      Thanks

        • Re: Why can only delete a General Table
          Artem Taturevych

          Try

           

          SwModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed

           

          instead of

           

          SwModel.EditDelete

          • Re: Why can only delete a General Table
            Yong Ning

            Private Sub del20160603()

               Dim Xls As Excel.Application, Rng As Range

                   Set Xls = GetObject(, "Excel.Application")

                   Set Rng = Xls.Selection

               Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                     Set SwApp = Application.SldWorks

                     Set SwModel = SwApp.ActiveDoc

               Dim SwSelMgr As SelectionMgr

                     Set SwSelMgr = SwModel.SelectionManager

               Dim SwGenTabFeat As GeneralTableFeature

                     Set SwGenTabFeat = SwSelMgr.GetSelectedObject5(1)

               Dim SwTabAnn As TableAnnotation

                     Set SwTabAnn = SwGenTabFeat.GetTableAnnotations(0)

                     delGeneralRowCol SwTabAnn

                     MergeRngToSwAnn Rng, SwTabAnn

                    

            End Sub

             

             

            Function MergeRngToSwAnn(Rng As Range, SwTabAnn As TableAnnotation)

               'Debug.Print SwTabAnn.GeneralTableFeature.GetFeature.Name

               ''

               Dim AnnRow, AnnCol

                  ''

                  With SwTabAnn

                     AnnRow = .RowCount: AnnCol = .ColumnCount

                  End With

               Dim RngRow, RngCol, Rr, Cc, ii, jj, Ccc As Double, ll As Double, Str, Ss

                  ''

                  RngRow = Rng.Rows.Count

                  RngCol = Rng.Columns.Count

                  ''

                  Rr = RngRow - AnnRow

                  If Rr > 0 Then

                       For ii = 1 To Rr

                          SwTabAnn.InsertRow 1, ii

                       Next ii

                  ElseIf Rr < 0 Then

                       For ii = 1 To Abs(Rr)

                          SwTabAnn.DeleteRow 0

                       Next ii

                  End If

                  ''

                  Cc = RngCol - AnnCol

                  If Cc > 0 Then

                       For ii = 1 To Cc

                          SwTabAnn.InsertColumn 1, 1, ii

                       Next ii

                  ElseIf Cc < 0 Then

                       For ii = 1 To Abs(Cc)

                          SwTabAnn.DeleteColumn 0

                       Next ii

                  End If

                  ''''

               Dim C1, C2, R1, R2, TextFormat As TextFormat

                  Cc = Rng.Columns.Count

                  For ii = 1 To Rng.Rows.Count

                     For jj = 1 To Cc

                        ''

                        If Rng(ii, jj).MergeCells Then

                          Ccc = Rng(ii, jj + 1 + Cc)

                          ll = 0

                          If Rng(ii, jj).Address = Rng(ii, jj).MergeArea(1, 1).Address Then

                             C1 = jj - 1

                             C2 = C1 + Rng(ii, jj).MergeArea.Columns.Count - 1

                             ''

                             R1 = ii - 1

                             R2 = R1 + Rng(ii, jj).MergeArea.Rows.Count - 1

                             SwTabAnn.MergeCells R1, C1, R2, C2

                             SwTabAnn.Text(R1, C1) = Rng(R1 + 1, C1 + 1) '.Address(0, 0)

                             'Stop

                            

                             If InStr(Rng(ii, jj), Chr(10)) > 0 Then

                                ll = 1.5

                             End If

                             Set TextFormat = WidthFactorTextFormat(SwTabAnn.GetCellTextFormat(R1, C1), Rng(ii, jj), Ccc, ll)

                             SwTabAnn.SetCellTextFormat R1, C1, False, TextFormat

                             ''

                          End If

                        Else

                          '

                          SwTabAnn.Text(ii - 1, jj - 1) = Rng(ii, jj) '.Address(0, 0)

                          ''

                          Set TextFormat = WidthFactorTextFormat(SwTabAnn.GetCellTextFormat(ii - 1, jj - 1), Rng(ii, jj), Ccc, ll)

                          SwTabAnn.SetCellTextFormat ii - 1, jj - 1, False, TextFormat

                         

                        End If

                     Next jj

                  Next ii

                  ''

            End Function

             

             

            Function MergeRngToSwAnnBorderLine(Rng As Range, SwTabAnn As TableAnnotation)

               'Debug.Print SwTabAnn.GeneralTableFeature.GetFeature.Name

               ''

               Dim AnnRow, AnnCol

                  ''

                  With SwTabAnn

                     AnnRow = .RowCount: AnnCol = .ColumnCount

                  End With

               Dim RngRow, RngCol, Rr, Cc, ii, jj, Ccc As Double, ll As Double, Str, Ss

                  ''

                  RngRow = Rng.Rows.Count

                  RngCol = Rng.Columns.Count

                  ''

                  Rr = RngRow - AnnRow

                  If Rr > 0 Then

                       For ii = 1 To Rr

                          SwTabAnn.InsertRow 1, ii

                       Next ii

                  ElseIf Rr < 0 Then

                       For ii = 1 To Abs(Rr)

                          SwTabAnn.DeleteRow 0

                       Next ii

                  End If

                  ''

                  Cc = RngCol - AnnCol

                  If Cc > 0 Then

                       For ii = 1 To Cc

                          SwTabAnn.InsertColumn 1, 1, ii

                       Next ii

                  ElseIf Cc < 0 Then

                       For ii = 1 To Abs(Cc)

                          SwTabAnn.DeleteColumn 0

                       Next ii

                  End If

                  ''''

               Dim C1, C2, R1, R2, TextFormat As TextFormat

                  Cc = Rng.Columns.Count

                  For ii = 1 To Rng.Rows.Count

                     For jj = 1 To Cc

                        ''

                        If Rng(ii, jj).MergeCells Then

                          Ccc = Rng(ii, jj + 1 + Cc)

                          ll = 0

                          If Rng(ii, jj).Address = Rng(ii, jj).MergeArea(1, 1).Address Then

                             C1 = jj - 1

                             C2 = C1 + Rng(ii, jj).MergeArea.Columns.Count - 1

                             ''

                             R1 = ii - 1

                             R2 = R1 + Rng(ii, jj).MergeArea.Rows.Count - 1

                             SwTabAnn.MergeCells R1, C1, R2, C2

                             SwTabAnn.Text(R1, C1) = Rng(R1 + 1, C1 + 1) '.Address(0, 0)

                             'Stop

                            

                             If InStr(Rng(ii, jj), Chr(10)) > 0 Then

                                ll = 1.5

                             End If

                             Set TextFormat = WidthFactorTextFormat(SwTabAnn.GetCellTextFormat(R1, C1), Rng(ii, jj), Ccc, ll)

                             SwTabAnn.SetCellTextFormat R1, C1, False, TextFormat

                             ''

                          End If

                        Else

                          '

                          SwTabAnn.Text(ii - 1, jj - 1) = Rng(ii, jj) '.Address(0, 0)

                          ''

                          Set TextFormat = WidthFactorTextFormat(SwTabAnn.GetCellTextFormat(ii - 1, jj - 1), Rng(ii, jj), Ccc, ll)

                          SwTabAnn.SetCellTextFormat ii - 1, jj - 1, False, TextFormat

                         

                        End If

                     Next jj

                     ''

                    

                  Next ii

                  ''

                    RngCol = Rng.Columns.Count

                    RngRow = Rng.Rows.Count

                    'Debug.Print SwTabAnn.GeneralTableFeature.GetFeature.Name

                    'Stop

                    With SwTabAnn

                       .BorderLineWeight = 1

                       For jj = 1 To RngCol

                          .SetColumnWidth jj - 1, Rng(0, jj) / 1000, swTableRowColChange_TableSizeCanChange

                       Next jj

                       ''

                       For jj = 1 To RngRow

                          .SetRowHeight jj - 1, (Rng(jj, 0) + 1) / 1000, swTableRowColChange_TableSizeCanChange

                       Next jj

                    End With

                 

                 

            End Function

             

             

            ''

            Function delGeneralRowCol(SwAnn As TableAnnotation)

               With SwAnn

                  For ii = .RowCount To 1 Step -1

                     .DeleteRow (ii)

                  Next ii

                  For jj = .ColumnCount To 1 Step -1

                     .DeleteColumn (jj)

                  Next jj

                  .Text(0, 0) = ""

               End With

            End Function