3 Replies Latest reply on May 16, 2014 9:36 AM by Patrick O'Hern

    How to get the General Table width  with API?

    Yong Ning

      Manual can set the General table width,

      000.jpg

       

      API set General table width  → set columnwidth→ sum columnwidth.

       

      Hope, how to get general table withdth with API

       

      Sub ll1()

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

        Dim SwView As View, SwTable As TableAnnotation, SwAnn As Annotation

          Set SwApp = GetObject(, "SldWorks.Application")

          Set SwModel = SwApp.ActiveDoc

          Set SwDraw = SwModel

          Set SwView = SwDraw.GetFirstView

          Set SwTable = SwView.GetFirstTableAnnotation

          Dim X, Y, Z As Integer, Anch

          X = 25: Y = 5

          SwTable.AnchorType = 3

          Dim ColWidth As Double

          Dim SwFeat As Feature

          With SwTable        ''

              .Merge 0

              .Split 1, 13        ''

              For jj = 0 To .ColumnCount

                .SetColumnWidth jj, 0.02, 0

                ColWidth = ColWidth + .GetColumnWidth(jj)

              Next jj        ''

              For ii = 0 To .RowCount - 1

                 .SetRowHeight ii, 0.005, 0

              Next ii

              .BorderLineWeight = 2

          End With 

          Do While Not SwTable Is Nothing   

             Set SwFeat = SwTable.GeneralTableFeature.GetFeature

             Debug.Print SwFeat.Name, SwTable.Title

             Set SwAnn = SwTable.GetAnnotation

             'Debug.Print SwTable.Title

             'ss = SwTable.GetAnnotation.GetPosition      

             SwAnn.SetPosition X / 1000, Y / 1000, 0

             'Stop

            Set SwTable = SwTable.GetNext

            X = X + ColWidth * 1000

          Loop       

      End Sub

        • Re: How to get the General Table width  with API?
          Patrick O'Hern

          I don't think you can get the width of the entire table, but you can get the width of each column (which you already seem to be doing), and add them together.

           

                  For jj = 0 To .ColumnCount

                    .SetColumnWidth jj, 0.02, 0

                    ColWidth = ColWidth + .GetColumnWidth(jj)

                    TotalWidth = TotalWidth + ColWidth  'add this row

                  Next jj

            • Re: How to get the General Table width  with API?
              Yong Ning

              Thanks your tips.

               

              It seems only SUM columns width, there is no other way.

               

               

              Function SwTableFindMergeRng(SwTable As TableAnnotation, Rng As Range)

                 Dim TextFormat As TextFormat, oTextFormat As TextFormat

                 Dim oRng As Range, wFactor, Cc

                 Cc = Rng.Columns.Count 

                 For ii = 1 To Rng.Rows.Count     ''

                    For jj = 1 To Rng.Columns.Count

                       Set oRng = Rng(ii, jj)

                       wFactor = oRng(1, Cc + 1)

                       ''

                       With oRng

                          If .MergeArea.Count > 1 Then

                            If .Address = .MergeArea.Cells(1, 1).Address Then

                              'Debug.Print oRng.Address, oRng, oRng.MergeArea.Rows.Count, oRng.MergeArea.Columns.Count

                              SwTable.MergeCells ii - 1, jj - 1, ii - 1 + .MergeArea.Rows.Count - 1, jj - 1 + .MergeArea.Columns.Count - 1

                              SwTable.Text(ii - 1, jj - 1) = .Value

                              ''

                              Set TextFormat = WidthFactorTextFormat(SwTable.GetCellTextFormat(ii - 1, jj - 1), oRng, wFactor, 1)

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

                            End If

                          Else

                            ''

                            With SwTable

                              If IsNumeric(oRng.Value) Then

                                .Text(ii - 1, jj - 1) = Format(oRng.Value, "0.0#")

                              Else

                                .Text(ii - 1, jj - 1) = oRng.Value

                              End If

                              ''

                              Set TextFormat = WidthFactorTextFormat(.GetCellTextFormat(ii - 1, jj - 1), oRng, wFactor, 1)

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

                            End With

                          End If

                       End With

                       ''

                       With SwTable

                              If Not TextFormat Is Nothing Then

                                 Select Case oRng.HorizontalAlignment

                                   Case xlLeft

                                     .CellTextHorizontalJustification(ii - 1, jj - 1) = 1

                                   Case xlCenter

                                     .CellTextHorizontalJustification(ii - 1, jj - 1) = 2

                                   Case xlRight

                                     .CellTextHorizontalJustification(ii - 1, jj - 1) = 3

                                 End Select

                              End If

                       End With       

                    Next jj    

                    'Debug.Print Rng(ii, -1), Rng(ii, -1).Address, ii, jj

                    'Stop

                    SwTable.SetRowHeight ii - 1, Rng(ii, -1) / 1000, 0

                 Next ii

              End Function

              ''