Set Note Name Example (VBA)
This example shows how to set the name of a
selected note. You can combine this code with a dialog that prompts the
user for a desired name, or you can programmatically determine the new
note name.
'------------------------------------------------------------------
Sub SetNoteName( newNoteName As
String )
Dim swApp As
Object
Dim Model As
Object
Dim SelMgr As
Object
Dim note As
Object
Dim checkNoteName
As String
Const swSelNOTES
= 15
Const swDocDRAWING
= 3
Set swApp =
CreateObject("SldWorks.Application")
Set Model =
swApp.ActiveDoc
If (Model Is
Nothing) Or (Model.GetType <>
swDocDRAWING) Then
Exit Sub
End If
Set SelMgr =
Model.SelectionManager
If (SelMgr.GetSelectedObjectCount = 0) Then
swApp.SendMsgToUser "Select a Note first..."
Else
If (SelMgr.GetSelectedObjectType(1) = 15) Then
Set note =
SelMgr.GetSelectedObject2(1)
res = note.SetName (newNoteName)
checkNoteName
= note.GetName
If (checkNoteName
<> newNoteName) Then
swApp.SendMsgToUser "Error changing note
name."
End If
End If
End If
End Sub