7 Replies Latest reply on Sep 19, 2017 4:25 AM by Bjorn Hulman

    Set revision table text to document font

    Bjorn Hulman

      Hi all,

      I'm trying to create 1 drawing template that formats itself depending on the process of manufacture, client (logos and unique identifier fields) and sheet size (A3, A2, A1)

      I have this working by replacing sheet formats and drafting standards depending on requirements. The template has a rev table, which is set to use document font settings. However, when the sheet size changes, the text size does something interesting which I can fix manually by selecting the table, unselecting use document font, then reselecting it. However I can't VBA code to do this.

      Mainly I've been trying 2017 SOLIDWORKS API Help - SetTextFormat Method (ITableAnnotation)

      But my novice level of VBA just can't get it to work.

      Ideally I'd have this as a sub which I can call when the sheet size has changed.

      Your help is greatly appreciated.

        • Re: Set revision table text to document font
          Bjorn Hulman

          Ok, so I asked on a Friday afternoon (UK Time) probably not the most productive time in anyones week no matter where in the world you are. But now it's a shiny new week!

          Anyone have any thoughts on how I can get my rev table to adjust to the correct settings?

            • Re: Set revision table text to document font
              Alex Burnett

              Can you post your code and how you're trying to do this? I have used the same method with success in updating IAnnotation objects.

               

              TextFormat tf = (TextFormat)swAnno.GetTextFormat(formatIndex);
              (IAnnotation)swAnno.SetTextFormat(formatIndex, true, tf);
              

               

              The "true" in the SetTextFormat statement checks the "Use Document Font" box for the particular feature.

               

              Perhaps it's in how you're getting your revision table object? You'll have to get the IAnnotation variable associated with it. I feel like the below method may be what you need.

               

              (This is c# syntax but the idea is the same)

              RevisionTable revTable = swSheet.RevisionTable;

              TableAnnotation table = (TableAnnotation)revTable;

              IAnnotation swAnno = table.GetAnnotation();

               

              Then use swAnno to set the document font.

               

              If that doesn't work, show us your code and we may be able to help further.

                • Re: Set revision table text to document font
                  Bjorn Hulman

                  thanks for the reply Alex.

                   

                  My code is in absolute disarray as I've chopped and changed it so often now one line is unlikely to make sense from the next, my mind is in an infinitely worse state.

                   

                  As I said, I'm a complete novice and have really got this working from other macros I've found on here and stitched it together.

                   

                  I'm at a loss at converting C# to VBA.

                   

                  I think I'm going to have to park this for a while. The macro does everything intended and I'm really pleased with it, I'd just really like to polish this dirty little artifact it leaves behind on the rear occasion the sheet size would be changed. All the other settings apply correctly when the drafting standard is applied and I'd have expected the rev table to follow suit.

                   

                  Thanks for your help.

                    • Re: Set revision table text to document font
                      Jacob Corder

                      Code Converter

                      use this. convert from vb to c#  and vice versa

                        • Re: Set revision table text to document font
                          Bjorn Hulman

                          Thanks Jacob,

                          Looks very helpful. I'll have another crack it this when my frazzled nerves calm down, and I've done enough design work to make up for the time I've spent on this.

                            • Re: Set revision table text to document font
                              Alex Burnett

                              You got my curiosity going on this one so I gave it a go. It looks like you can set the global "Use Document Font" for the table and the value reflects that it changed in the code. However, the toggle on the table doesn't change and neither does any of the fonts within it.

                               

                              The next check I did was to apply the text format to each cell individually and that worked. I'm not sure if it helps but here's the code.

                               

                              Dim swDraw As DrawingDoc
                              Dim swSheet As Sheet
                              Dim revTable As RevisionTableAnnotation
                              Dim table As TableAnnotation
                              Dim swAnno As Annotation
                              Dim tf As TextFormat
                              
                              
                              Dim boolstatus As Boolean
                              Dim boolUseDocTextFormat
                              Dim longstatus As Long, longwarnings As Long
                              
                              
                              Sub main()
                              
                              
                              Set swApp = Application.SldWorks
                              Set swModel = swApp.ActiveDoc
                              
                              
                              If swModel.GetType = swDocDRAWING Then
                                  Set swDraw = swModel
                                  Set swSheet = swDraw.GetCurrentSheet
                                  Set revTable = swSheet.RevisionTable
                                  Set table = revTable
                                  
                                  'boolUseDocTextFormat = table.GetUseDocTextFormat()
                                  'Debug.Print "Before: " & boolUseDocTextFormat
                                  
                                  Dim Row, Col As Integer
                                  For Row = 0 To table.RowCount - 1
                                      For Col = 0 To table.ColumnCount - 1
                                          Set tf = table.GetCellTextFormat(Row, Col)
                                          table.SetCellTextFormat Row, Col, True, tf
                                      Next Col
                                  Next Row
                                  
                                  Set tf = table.GetTextFormat()
                                  table.SetTextFormat True, tf
                                  
                                  'boolUseDocTextFormat = table.GetUseDocTextFormat()
                                  'Debug.Print "After: " & boolUseDocTextFormat
                                  
                              End If