5 Replies Latest reply on Jan 16, 2017 7:47 AM by Blagovest Zlatev

    Rotate a cell in a general table through a VBA macro.

    Blagovest Zlatev

      I need to rotate multiple cells of a table with the help of a macro. The problem is I don't find anything in the ITableAnnotation or ITextFormat members. I tried writing "<r90>Test Text</r>" as a string but that didn't work also.

       

      In short I need to do that but with a macro.

       

      Untitled.png

          • Re: Rotate a cell in a general table through a VBA macro.
            Blagovest Zlatev

            I tried that. The result was still the same. The only way it works is if I set the textformat for the whole table.

             

            Option Explicit

             

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim swDrawing As SldWorks.DrawingDoc

            Dim swTblAnn As SldWorks.TableAnnotation

            Dim textFormat As SldWorks.textFormat

             

             

            Sub main()

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swDrawing = swModel

                Set swTblAnn = swDrawing.InsertTableAnnotation2(True, 0, 0, 1, "", 3, 3)

             

                swTblAnn.Text(1, 1) = "Text Rotated!"

                Set textFormat = swTblAnn.GetCellTextFormat(1, 1)

                textFormat.Escapement = 90 / 57.3

                swTblAnn.SetCellTextFormat 1, 1, False, textFormat

             

                Debug.Print "done"

            End Sub

             

            The result is still the same.

             

            Untitled.png

          • Re: Rotate a cell in a general table through a VBA macro.
            Amen Allah Jlili

            Get the TextFormat of the cell using .GetCellTextFormat and then set the TextFormat object's escapement property to your desired amount of rotation in radians. Last, use SetCellTextFormat to apply that to the cell.

              • Re: Rotate a cell in a general table through a VBA macro.
                Blagovest Zlatev

                I tried that. The result was still the same. The only way it works is if I set the textformat for the whole table.

                 

                I used this test macro.

                 

                Option Explicit

                 

                Dim swApp As SldWorks.SldWorks

                Dim swModel As SldWorks.ModelDoc2

                Dim swDrawing As SldWorks.DrawingDoc

                Dim swTblAnn As SldWorks.TableAnnotation

                Dim textFormat As SldWorks.textFormat

                 

                 

                Sub main()

                    Set swApp = Application.SldWorks

                    Set swModel = swApp.ActiveDoc

                    Set swDrawing = swModel

                    Set swTblAnn = swDrawing.InsertTableAnnotation2(True, 0, 0, 1, "", 3, 3)

                  

                    swTblAnn.Text(1, 1) = "Text Rotated!"

                  

                    Set textFormat = swTblAnn.GetCellTextFormat(1, 1)

                    textFormat.Escapement = 90 / 57.3

                    swTblAnn.SetCellTextFormat 1, 1, False, textFormat

                  

                    Debug.Print "done"

                End Sub

              • Re: Rotate a cell in a general table through a VBA macro.
                Blagovest Zlatev

                I found a way to get it working but in my opinion it's broken.

                 

                First I set the text format for the whole table as rotated 90 degrees. Then I go and set the TextFormat with 0 degree escapement for the cells that I don't want to be rotated and then it works. Completely illogical but I'll leave the test macro for anyone who has my problem.

                 

                This macro:

                 

                Option Explicit

                 

                Dim swApp As SldWorks.SldWorks

                Dim swModel As SldWorks.ModelDoc2

                Dim swDrawing As SldWorks.DrawingDoc

                Dim swTblAnn As SldWorks.TableAnnotation

                Dim textFmt As SldWorks.textFormat

                 

                Sub main()

                    Set swApp = Application.SldWorks

                    Set swModel = swApp.ActiveDoc

                    Set swDrawing = swModel

                    Set swTblAnn = swDrawing.InsertTableAnnotation2(True, 0, 0, 1, "", 3, 3)

                   

                    Dim i As Integer

                    Dim k As Integer

                   

                    For i = 0 To swTblAnn.RowCount - 1

                        For k = 0 To swTblAnn.ColumnCount - 1

                            swTblAnn.Text(i, k) = "Text Rotated!"

                        Next

                    Next

                   

                    Set textFmt = swTblAnn.GetCellTextFormat(1, 1)

                    textFmt.Escapement = 90 / 57.3

                    swTblAnn.SetTextFormat False, textFmt

                   

                    textFmt.Escapement = 0

                   

                    swTblAnn.SetCellTextFormat 1, 1, False, textFmt

                    swTblAnn.SetCellTextFormat 1, 0, False, textFmt

                   

                    Debug.Print "done"

                End Sub

                 

                Gives me this result:

                Untitled.png