4 Replies Latest reply on Feb 17, 2015 6:39 AM by Mario Zahren

    How to change Font for each text in drawings using API?

    Mario Zahren

      I want to Change all the text in the drawing e.g.

       

      Annotations

      Dimensions

      Tables

      Sketches

      ...

       

      Any ideas?

       

      Thanks in advance

      Cheers

      Mario

        • Re: How to change Font for each text in drawings using API?
          Santosh Pawar

          SetTextFormat Method (IAnnotation)

           

          2014 SOLIDWORKS API Help - Change Text Format Example (VBA)

           

          you can iterate over all annotations using GetFirstAnnotation2 and GetNext3

           

            • Re: How to change Font for each text in drawings using API?
              Mario Zahren

              Hi,

               

              I´m sorry. I've been trying lots of code but nothing will work. The code insists on a marked text.

              How can I use GetFirstAnnotation2 and GetNext3 in thise case?

               

              Please excuse my lack of knowledge in coding. I´m a beginner.

              Mario

                • Re: How to change Font for each text in drawings using API?
                  Santosh Pawar

                  Try this,

                   

                  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

                      Dim swDraw As DrawingDoc

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc
                  Set swDraw = swModel
                      Set swView = swDraw.GetFirstView
                      Do While Not Nothing Is swView
                          Set swAnn = swView.GetFirstAnnotation3
                          Do While Not Nothing Is swAnn
                              ProcessAnnotation swApp, swAnn
                              Set swAnn = swAnn.GetNext3
                          Loop
                          Set swView = swView.GetNextView
                      Loop

                  End Sub

                  Sub ProcessAnnotation(swApp As SldWorks.SldWorks, swAnn As SldWorks.Annotation)
                  Do While Not swAnn Is Nothing

                      ' Get text format information

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

                      For i = 0 To swAnn.GetTextFormatCount - 1

                          Set swTextFormat = swAnn.GetTextFormat(i)

                          ' Change text to be 10mm high, bold, italic, and Comic Sans MS font face

                          swTextFormat.CharHeight = 0.01

                          swTextFormat.Bold = True

                          swTextFormat.Italic = True

                          swTextFormat.TypeFaceName = "Comic Sans MS"

                          bRet = swAnn.SetTextFormat(i, False, swTextFormat): Debug.Assert bRet

                      Next
                          Set swAnn = swAnn.GetNext3
                      Loop
                  End Sub