2 Replies Latest reply on Sep 25, 2018 11:37 AM by Layne Fowler

    Setting CurrentParagraph with word wrap not working

    Layne Fowler

      It seems that setting the CurrentParagraph property actually sets the current line, not paragraph, when applied to a note with word wrap.

       

      Simple code to demonstrate:

       

      Dim swApp As Object
      Dim swModel As Object
      Dim swSelMgr As SldWorks.SelectionMgr
      Dim swAnnObj As Object
      Dim swAnn As SldWorks.Annotation
      Dim swParagraphs As SldWorks.Paragraphs
      Dim nParagraphs As Long
      Dim iParagraphs As Long
      Dim bRet As Boolean
      Dim sRet As String
      
      Sub main()
          
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swSelMgr = swModel.SelectionManager
          Set swAnnObj = swSelMgr.GetSelectedObject6(1, -1)
          Set swAnn = swAnnObj.GetAnnotation
          Set swParagraphs = swAnn.GetParagraphs
          
          nParagraphs = swParagraphs.Count
          
          For iParagraphs = 0 To nParagraphs - 1
              
              swParagraphs.CurrentParagraph = iParagraphs
              sRet = swParagraphs.GetText(True)
              bRet = swParagraphs.SetBulletsAndNumbering(1, 0, 1, 1, 1)
              bRet = swParagraphs.UpdateParagraph()
              
          Next
          
      End Sub
      
      

       

      This will number each line in a selected note. If you stretch the width of the note so there is no word wrapping this snippet will work fine. If you narrow the width of the note so that lines begin to wrap this macro behaves incorrectly.

       

      It looks like Count counts the true number of paragraphs while CurrentParagraph sets the line number. However, if you try to manually set the line number greater than the total number of paragraphs, that does not work either.

       

      Am I correct in concluding this API property is broken or am I missing something here?

        • Re: Setting CurrentParagraph with word wrap not working
          Fifi Riri

          Hello

          Yes you're right: text wrap mess up the numbering function

           

          A workaround would be to extend the boundaries of the note, or un-wrap then re-wrap the text, but there is no API for either.

          An other workaround that could work for you, is to shrink the text so it fits in the note boundaries, create the numbering, then re-apply the original font:

           

          Option Explicit

          Dim swApp As Object

          Dim swModel As Object

          Dim swSelMgr As SldWorks.SelectionMgr

          Dim swNote As SldWorks.Note

          Dim swAnn As SldWorks.Annotation

          Dim swParagraphs As SldWorks.Paragraphs

          Dim iParagraphs As Long

          Dim bRet As Boolean

          Dim swTxtFormat As SldWorks.TextFormat

          Dim myFormat As Double

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

           

              'swModel.ClearSelection2 True

              'bRet = swModel.Extension.SelectByID2("DetailItem607@Sheet1", "NOTE", 0, 0, 0, False, 0, Nothing, 0)

           

              Set swNote = swSelMgr.GetSelectedObject6(1, -1)

              Set swAnn = swNote.GetAnnotation

           

              Set swTxtFormat = swAnn.GetTextFormat(0)

              myFormat = swTxtFormat.CharHeightInPts

              swTxtFormat.CharHeightInPts = 1

              swAnn.SetTextFormat 0, False, swTxtFormat

           

              Set swParagraphs = swAnn.GetParagraphs

              For iParagraphs = 0 To swParagraphs.Count - 1

                  swParagraphs.CurrentParagraph = iParagraphs

                  bRet = swParagraphs.SetBulletsAndNumbering(1, 0, 1, 1, 1)

                  bRet = swParagraphs.UpdateParagraph()

              Next

           

              swTxtFormat.CharHeightInPts = myFormat

              swAnn.SetTextFormat 0, False, swTxtFormat

          End Sub