9 Replies Latest reply on Mar 21, 2018 2:23 AM by Jukka M.

    Document balloon text size

    Jukka M.

      Hi,

       

      I've searched this and many other forums for a macro that changes annotation texts for example to the size of 10 points. I'm losing all hope, because everything else seems to be possible to macro than that. I've had many good macros from this forum, and they have been great help in my everyday tasks

       

      But this one. I need to change my drawings text size to 10 points, reference balloons with spacing 2 characters, and also text font to Arial. I've tried earlier a macro that changed dimensions text size, but it didn't change balloon sizes. Is it possible to change that via macro?

        • Re: Document balloon text size
          Bjorn Hulman

          Hi Jukka,

          One way would be to change the balloon text size via document properties drafting standards. So if you create a drafting standard (or set of) with the right fonts sizes layers etc etc you could then load the drafting standard you require via a macro.

          • Re: Document balloon text size
            Matt Bieringer

            Have you tried using the .SetTextFormat method found here? 2017 SOLIDWORKS API Help - SetTextFormat Method (IAnnotation)

              • Re: Document balloon text size
                Jukka M.

                Hi and thank you for answering this. Behind that API Help -link I found this example macro.

                 

                ---------------------------------------------------

                ' Preconditions:

                ' 1. Open a part, assembly, or drawing that has at least

                ' one annotation containing text.

                ' 2. Select that annotation.

                ' 3. Open the Immediate window.

                '

                ' Postconditions:

                ' 1. Changes the text format of the selected annotation.

                ' 2. Examine the annotation in the graphics area and

                ' the Immediate window.

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

                Option Explicit

                Sub main()

                 

                    Dim swApp                       As SldWorks.SldWorks
                    Dim swModel                     As SldWorks.ModelDoc2
                    Dim swSelMgr                    As SldWorks.SelectionMgr
                    Dim swAnnObj                    As Object
                    Dim swAnn                       As SldWorks.Annotation
                    Dim swTextFormat                As SldWorks.TextFormat
                    Dim i                           As Long
                    Dim bRet                        As Boolean

                 

                    Set swApp = Application.SldWorks
                    Set swModel = swApp.ActiveDoc
                    Set swSelMgr = swModel.SelectionManager
                    Set swAnnObj = swSelMgr.GetSelectedObject6(1, -1)
                    Set swAnn = swAnnObj.GetAnnotation

                 

                    'Get text format information
                    Debug.Print "File = " & swModel.GetPathName
                    Debug.Print "  " & swAnn.GetName & " <" & swAnn.GetType & ">"

                 

                    For i = 0 To swAnn.GetTextFormatCount - 1
                        Set swTextFormat = swAnn.GetTextFormat

                 

                 

                        'Change text to be 10mm, bold, italic, and Comic Sans MS font
                        swTextFormat.CharHeight = 0.01
                        swTextFormat.Bold = True
                        swTextFormat.Italic = True
                        swTextFormat.TypeFaceName = "Comic Sans MS"
                        bRet = swAnn.SetTextFormat(i, False, swTextFormat)
                    Next

                 

                End Sub

                --------------------------------------------------------------------------------------------------------------------------------------

                 

                It works like a charm, but any ideas how can I make it go through every reference balloon? It only changes one balloon at the time, and I have to go through every balloon one by one to change whole drawing. Even if I select all reference balloons at once, it changes only one of them.

                  • Re: Document balloon text size
                    Matt Bieringer

                    That's not too hard thankfully.

                    Option Explicit
                    Sub main()
                        Dim swApp                       As SldWorks.SldWorks
                        Dim swModel                     As SldWorks.ModelDoc2
                        Dim swDraw                      As SldWorks.DrawingDoc
                        Dim swView                      As SldWorks.View
                        Dim swNote                      As SldWorks.Note
                        Dim swAnn                       As SldWorks.Annotation
                        Dim swTextFormat                As SldWorks.TextFormat
                        Dim i                           As Long
                        Dim bRet                        As Boolean
                     
                        Set swApp = Application.SldWorks
                        Set swModel = swApp.ActiveDoc
                        Set swDraw = swModel
                        Set swView = swDraw.GetFirstView
                        While Not swView Is Nothing
                        Set swNote = swView.GetFirstNote
                            While Not swNote Is Nothing
                            If swNote.IsBomBalloon Then
                                Set swAnn = swNote.GetAnnotation
                                'Get text format information
                                Debug.Print "File = " & swModel.GetPathName
                                Debug.Print "  " & swAnn.GetName & " <" & swAnn.GetType & ">"
                                For i = 0 To swAnn.GetTextFormatCount - 1
                                    Set swTextFormat = swAnn.GetTextFormat(i)
                                    'Change text to be 10mm, bold, italic, and Comic Sans MS font
                                    swTextFormat.CharHeight = 0.01
                                    swTextFormat.Bold = True
                                    swTextFormat.Italic = True
                                    swTextFormat.TypeFaceName = "Comic Sans MS"
                                    bRet = swAnn.SetTextFormat(i, False, swTextFormat)
                                Next
                            End If
                            Set swNote = swNote.GetNext
                            Wend
                        Set swView = swView.GetNextView
                        Wend
                    End Sub
                    
                      • Re: Document balloon text size
                        Jonathan Westcott

                        Hi Matt,

                         

                        Just wondering is there a similar method that can be used to just modify Revision Symbols?

                        • Re: Document balloon text size
                          Jukka M.

                          Great success!

                           

                          Thank you so very much! One thing came in to my mind, can balloon size be added to this too?

                            • Re: Document balloon text size
                              Matt Bieringer

                              That is also not hard. After you set the text format use 2017 SOLIDWORKS API Help - SetBalloon Method (INote)  to set the balloon fit and other properties. Just know that this is a member of Note not Annotation so use swNote.SetBalloon

                                • Re: Document balloon text size
                                  Jukka M.

                                  Great! Thanks for help. This is how it looks after all, if anyone else finds this helpful. I added some lines to change reference balloons to circle and 2 characters fit.

                                   

                                  Option Explicit

                                  Sub main()

                                      Dim swApp                           As SldWorks.SldWorks

                                      Dim swModel                        As SldWorks.ModelDoc2

                                      Dim swDraw                         As SldWorks.DrawingDoc

                                      Dim swView                          As SldWorks.View

                                      Dim swNote                          As SldWorks.Note

                                      Dim swAnn                           As SldWorks.Annotation

                                      Dim swTextFormat               As SldWorks.TextFormat

                                      Dim i                                     As Long

                                      Dim bRet                              As Boolean

                                      Dim boolstatus                     As Boolean

                                   

                                   

                                      Set swApp = Application.SldWorks

                                      Set swModel = swApp.ActiveDoc

                                      Set swDraw = swModel

                                      Set swView = swDraw.GetFirstView

                                      While Not swView Is Nothing

                                      Set swNote = swView.GetFirstNote

                                          While Not swNote Is Nothing

                                          If swNote.IsBomBalloon Then

                                              Set swAnn = swNote.GetAnnotation

                                              'Get text format information

                                              Debug.Print "File = " & swModel.GetPathName

                                              Debug.Print "  " & swAnn.GetName & " <" & swAnn.GetType & ">"

                                              For i = 0 To swAnn.GetTextFormatCount - 1

                                                  Set swTextFormat = swAnn.GetTextFormat(i)

                                                  'Change text

                                                  swTextFormat.CharHeight = 0.01

                                                  swTextFormat.Bold = False

                                                  swTextFormat.Italic = False

                                                  swTextFormat.TypeFaceName = "Arial"

                                                  boolstatus = swNote.SetBalloon(1, 2)

                                                  bRet = swAnn.SetTextFormat(i, False, swTextFormat)

                                              Next

                                          End If

                                          Set swNote = swNote.GetNext

                                          Wend

                                      Set swView = swView.GetNextView

                                      Wend

                                  End Sub