Hide Table of Contents

Change Note Text Example (VBA)

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

 

'--------------------------------------------------

Option Explicit

Const NumStrings As Long = 3

Dim GermanString(NumStrings)    As String

Dim EnglishString(NumStrings)   As String

Private Sub InitStrings()

    ' German strings, copied and pasted from SOLIDWORKS drawing

    GermanString(0) = "ERROR!:SW-Blattmaßstab"

    GermanString(1) = "ERROR!:SW-Aktuelles Blatt"

    GermanString(2) = "ERROR!:SW-Gesamtzahl der Blätter"

    

    ' equivalent English strings, copied and pasted from SOLIDWORKS drawing

    EnglishString(0) = "$PRP:" + Chr(34) + "SW-Sheet Scale" + Chr(34)

    EnglishString(1) = "$PRP:" + Chr(34) + "SW-Total Sheets" + Chr(34)

    EnglishString(2) = "$PRP:" + Chr(34) + "SW-Current Sheet" + Chr(34)

End Sub

Private Sub DoReplaceString(ByRef sNoteText As String)

    Dim i               As Long

    

    For i = 0 To NumStrings

        sNoteText = Replace(sNoteText, GermanString(i), EnglishString(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

    

    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.GetTextAngleAtIndex(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) 2015 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.