Hide Table of Contents

Change Note Text Example (VBA)

This example shows how to change the note on a drawing template by opening the drawing template for editing and then selecting the note and using the INote::SetText method to modify the note.

'---------------------------------------------------------------------
' Preconditions: Open public_documents\samples\tutorial\api\2012-sm.slddrw.
'
' Postconditions:
' 1. Examine the title block in the drawing.
' 2. Gets the first drawing view, which is the drawing template.
' 3. Iterates all notes in the drawing template, replacing notes
'    matching initString with newString.
' 4. Examine the title block again to verify step 3.
'
' NOTE: Because the drawing is used elsewhere, do not save changes.
'---------------------------------------------------------------------
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


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Change Note Text Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2019 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.