2 Replies Latest reply on Aug 13, 2015 8:03 AM by Alice Caspari

    Macro to change notes to document font

    Alice Caspari

      I have a macro to traverse each drawing view and change the notes in that view to use the document font.

      It works but it changes the fonts in the sheet format/ titleblock as well which I don't want it to do.

      Any ideas on where I went wrong?

       

       

      Option Explicit

      ' Select all annotations and set to use Document Font - 08/12/15 by Casparia

         
          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2
          Dim swDraw As SldWorks.DrawingDoc
          Dim swView As SldWorks.View

          Dim swTextFormat As SldWorks.textFormat

          Dim i As Long
          Dim j As Long
          Dim annotations As Variant  
          Dim notes As SldWorks.annotation  
          Dim count As Long  
          Dim bool As Boolean

       

        Sub main()

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc
          Set swDraw = swModel

         
          ' Iterate through all the views on the drawing to find annotations

          Set swView = swDraw.GetFirstView

          Do While Not swView Is Nothing
         
              count = swView.GetAnnotationCount
                    
          ' Iterate through all the annotations in each drawing view that has them and set to use document font

          If count > 0 Then

                  annotations = swView.GetAnnotations

                  For j = 0 To UBound(annotations)

                      Set notes = annotations(j)
                      bool = notes.SetTextFormat(i, True, swTextFormat)

                  Next j

              End If

              Set swView = swView.GetNextView

          Loop

      End Sub

        • Re: Macro to change notes to document font
          Ivana Kolin

          first view is sheet, you have to start with second view.

           

          Option Explicit
          ' Select all annotations and set to use Document Font - 08/12/15 by Casparia
              
              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim swDraw As SldWorks.DrawingDoc
              Dim swView As SldWorks.View
              Dim swTextFormat As SldWorks.TextFormat
              Dim i As Long
              Dim j As Long
              Dim annotations As Variant
              Dim notes As SldWorks.Annotation
              Dim count As Long
              Dim bool As Boolean
          
            Sub main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swDraw = swModel
              
              ' Iterate through all the views on the drawing to find annotations
              Set swView = swDraw.GetFirstView
              Set swView = swView.GetNextView
              Do While Not swView Is Nothing
              Debug.Print swView.Name
                  count = swView.GetAnnotationCount
                         
              ' Iterate through all the annotations in each drawing view that has them and set to use document font
              If count > 0 Then
                      annotations = swView.GetAnnotations
                      For j = 0 To UBound(annotations)
                          Set notes = annotations(j)
                          bool = notes.SetTextFormat(i, True, swTextFormat)
                      Next j
                  End If
                  Set swView = swView.GetNextView
              Loop
          End Sub