Hide Table of Contents

Get Note By Name Example (VBA)

This example shows how to get a note by its name using two separate methods: note traversal and note selection. The note selection method is faster since it avoids traversing all the notes on the template. Once the first note is selected, the example gets the text from the note and uses it to modify another note on the drawing.

 

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

Public Sub GetNotes()

 

' Define variable used to hold the SldWorks object

Dim swApp As Object    

 

' Define variable used to hold the ModelDoc and DrawingDoc objects

Dim Model, DwgDoc As Object   

 

' Define variable used to hold the SelectionManager object

Dim SelMgr As Object   

Dim note, view As Object

 

Const swSelNOTES = 15   

Const swDocDRAWING = 3

 

 

' Attach to or open SolidWorks session

Set swApp = CreateObject("SldWorks.Application") 

 

' Grab the current document

Set Model = swApp.ActiveDoc     

 

' Verify that the document is a drawing

If (Model Is Nothing) Or (Model.GetType <> swDocDRAWING) Then

Exit Sub

End If

 

' DrawingDoc and ModelDoc are same in VB

Set DwgDoc = Model     

' Edit the current drawing template

DwgDoc.EditTemplate     

' This is the template

Set view = DwgDoc.GetFirstView     

 

' This section shows a slower method for selecting a note by name by using note traversal (GetFirstNote/GetNext)

 

' Get the first note object

Set note = view.GetFirstNote()   

 

' While you have a valid note

Do While Not note Is Nothing  

If (note.GetName = "RevNum") Then   

' Verify if you have the desired note by checking its name. This could also be done by checking position or the existing text string in the note (for example, If (noteText = "<INSERT PART NAME HERE>").

theCurrentRev = note.GetText

 

If foundNote = True then

  Exit Do

End If

 

Set note = note.GetNext

 

' Continue until no more notes exist

Loop   

 

 

' This section shows a faster method for selecting a note by name by using SelectByID

If (foundNote) Then

 

ret = Model.SelectById ("RevDescription@Template1", "NOTE", 0, 0, 0)

 

'Get the SelectionMgr class

Set SelMgr = Model.SelectionManager()  

 

' If user has selected something

If (SelMgr.GetSelectedObjectCount <> 0) Then  

' Get the first item in the selection list

Set selObj = SelMgr.GetSelectedObject2(1)  

 

' If selected object is a note

If (SelMgr.GetSelectedObjectType(1) = swSelNOTES) Then 

descriptionText = "This drawing has been updated to " + theCurrentRev + " per blah-blah"

' Change the text in the note

ret = selObj.SetText(descriptionText )   

 

' If change is successful

If (ret = True) Then    

swApp.SendMsgToUser ("Successfully changed note text"

 

' If name change failed

Else        

swApp.SendMsgToUser ("Error changing note text.")

End If

 

End If

 

' If selection change failed

Else         

 

swApp.SendMsgToUser ("Error selecting RevDescription note.")

 

' End if we selected the RevDescription note successfully

End If     

 

' End if the RevNum note was found

End If     

 

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:   Get Note By Name 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) 2012 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.