Change text in Note

Have Note name---change Note Text

Method 1

Sub fdsafdsafds()
    Dim swApp                       As SldWorks.SldWorks
    Dim swModel                     As SldWorks.ModelDoc2
    Dim swDraw                      As SldWorks.DrawingDoc      '工程图对象
    Dim SelMgr As SldWorks.SelectionMgr
    Dim temp, selObj
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    'Set SelMgr = swModel.SelectionManager


   
 
  With swDraw
    Set SelMgr = .SelectionManager
    temp = .Extension.SelectByID2("s1@图纸1", "NOTE", 0, 0, 0, False, 0, Nothing, 0)
    'temp = swModel.Extension.SelectByID2("s1", "NOTE", 0, 0, 0, False, 0, Nothing, 0)  if not view name, don't select Note
    Set selObj = SelMgr.GetSelectedObject2(1)
    'Call the SldWorks.Note.SetText method to change the text
    temp = selObj.SetText("Have Change Text")
   
  End With

End Sub

Method 2 Traversal

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 bRet                         As Boolean

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel

    Set swView = swDraw.GetFirstView  '得到第一个视图

    Debug.Print swView.Name

    Set swNote = swView.GetFirstNote     '得到第一个注释

    swModel.ClearSelection2 (True)

    Debug.Print "File = " & swModel.GetPathName

    Do While Not swNote Is Nothing

        Set swAnn = swNote.GetAnnotation            '得到标注

       

        Debug.Assert bRet

        SwName = swNote.GetName

        SwText = swNote.GetText

        If SwName = "s1" Then

          bRet = swAnn.Select2(True, 0)               '高亮选中

          Debug.Print swView.GetName2

          Debug.Print "  名称:" & swNote.GetName; " *** 文本: " & swNote.GetText

        End If

        Set swNote = swNote.GetNext '下一个注释

    Loop

End Sub

SolidworksApi macros