5 Replies Latest reply on Apr 13, 2017 1:56 PM by Cad Admin

    VBA to check LeaderStyle in a Note

    Cad Admin

      How dto check the LeaderLineStyle of a Note, not too much in the API Help, and nothing on the Forum

        • Re: VBA to check LeaderLineStyle in a Note
          Manikandan Babu

          Hi Cad Admin,

           

          Dim swApp As SldWorks.SldWorks

          Dim swmodel As SldWorks.ModelDoc2

          Dim swnote As SldWorks.Note

          Dim swann As SldWorks.Annotation

          Dim swselmgr As SldWorks.SelectionMgr

           

          Sub main()

          Set swApp = Application.SldWorks

          Set swmodel = swApp.ActiveDoc

          Set swselmgr = swmodel.SelectionManager

          Set swnote = swselmgr.GetSelectedObject6(1, -1)

          Set swann = swnote.GetAnnotation

          Debug.Print swann.Leaderlinestyle                '6

           

          End Sub

           

          swLineCENTER4
          swLineCHAIN3
          swLineCHAINTHICK6
          swLineCONTINUOUS0
          swLineDEFAULT7
          swLineHIDDEN1
          swLinePHANTOM2
          swLineSTITCH5

           

          Thanks

          Manikandan

            • Re: VBA to check LeaderLineStyle in a Note
              Cad Admin

              How would i check leader vs no leader?

                • Re: VBA to check LeaderLineStyle in a Note
                  Manikandan Babu

                  Dim swApp As SldWorks.SldWorks

                  Dim swmodel As SldWorks.ModelDoc2

                  Dim swnote As SldWorks.Note

                  Dim swann As SldWorks.Annotation

                  Dim swselmgr As SldWorks.SelectionMgr

                  Sub main()

                   

                   

                  Set swApp = Application.SldWorks

                  Set swmodel = swApp.ActiveDoc

                  Set swselmgr = swmodel.SelectionManager

                  Set swnote = swselmgr.GetSelectedObject6(1, -1)

                  Set swann = swnote.GetAnnotation

                  Debug.Print swann.GetLeaderStyle   swNO_LEADER 0 = No leader

                  End Sub

                    • Re: VBA to check LeaderLineStyle in a Note
                      Cad Admin

                      Manikandan,

                       

                      Basically i'm looking to add a leader/no leader check to this ....only want it to process notes with leaders

                       

                       

                      Option Explicit

                       

                      Const NumStrings As Long = 3

                      Dim initString(NumStrings) As String

                      Dim newString(NumStrings) As String

                       

                      Private Sub InitStrings()

                          ' Initial strings from drawing

                          initString(0) = "2012-sm"

                          initString(1) = "WEIGHT:"

                          initString(2) = "FINISH:"

                       

                          ' Strings to replace initial strings in drawing

                          newString(0) = "NEW 2012-sm"

                          newString(1) = "NEW WEIGHT:"

                          newString(2) = "NEW FINISH:"

                      End Sub

                       

                      Private Sub DoReplaceString(ByRef sNoteText As String)

                          Dim i As Long

                       

                          For i = 0 To NumStrings

                              sNoteText = Replace(sNoteText, initString(i), newString(i), 1, -1, vbTextCompare)

                          Next i

                      End Sub

                       

                      Sub main()

                       

                          Dim swApp As SldWorks.SldWorks

                          Dim swModel As SldWorks.ModelDoc

                          Dim swDraw As SldWorks.DrawingDoc

                          Dim swView As SldWorks.View

                          Dim swNote As SldWorks.Note

                          Dim sNoteText As String

                          Dim nTextCount As Long

                          Dim i As Long

                       

                          InitStrings

                       

                          Set swApp = CreateObject("SldWorks.Application")

                          Set swModel = swApp.ActiveDoc

                          Set swDraw = swModel

                          Set swView = swDraw.GetFirstView ' This is the drawing template

                       

                          While Not swView Is Nothing

                              Set swNote = swView.GetFirstNote

                              While Not swNote Is Nothing

                                  If swNote.IsCompoundNote Then

                                      nTextCount = swNote.GetTextCount

                                      For i = 1 To nTextCount

                                          sNoteText = swNote.GetTextAtIndex(i)

                                          DoReplaceString sNoteText

                                          swNote.SetTextAtIndex i, sNoteText

                                      Next i

                                  Else

                                      sNoteText = swNote.GetText

                                      DoReplaceString sNoteText

                                      swNote.SetText sNoteText

                                  End If

                                  Set swNote = swNote.GetNext

                              Wend

                              Set swView = swView.GetNextView

                          Wend   

                       

                      End Sub

                        • Re: VBA to check LeaderLineStyle in a Note
                          Cad Admin

                          Added the Getleaderstyle check in & works great...

                           

                          Dim swAnn                   As SldWorks.Annotation

                          Dim LeadStyle             As String

                           

                           

                          While Not swNote Is Nothing

                                      If swNote.IsCompoundNote Then

                                          nTextCount = swNote.GetTextCount

                                          For i = 1 To nTextCount

                                              sNoteText = swNote.GetTextAtIndex(i)

                                              Debug.Print "Text =  " & sNoteText

                          DoReplaceString sNoteText

                          swNote.SetTextAtIndex i, sNoteText

                                          Next i

                                          Debug.Print "Text =  " & sNoteText

                                      Else

                                          Set swAnn = swNote.GetAnnotation

                                          LeadStyle = swAnn.GetLeaderStyle

                                          sNoteText = swNote.GetText

                                          If LeadStyle > 0 Then

                                                Debug.Print "Text =  " & sNoteText

                                               DoReplaceString sNoteText

                                             

                                          swNote.SetText sNoteText

                                          Else

                                         End If

                                      End If

                                      Set swNote = swNote.GetNext

                                  Wend