Get Corresponding Note in Part Example (VBA)
This example shows how to determine if the selected note in a part corresponds
to the selected note in an assembly to which the part belongs.
'-----------------------------------------
'
' Preconditions:
' (1)
Part document named Block.SLDPRT exists and is not open.
' (2)
Block.SLDPRT is a component of the open, active, assembly document.
' (3)
Annotations are displayed in both the part and assembly documents.
' (4)
Block.SLDPRT has a Note1 note.
'
' Postconditions: None
'
'------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swPart As SldWorks.PartDoc
Dim swAssemNote As SldWorks.note
Dim swPartNote As SldWorks.note
Dim swPartNoteCorresp As Object
Dim swAnnotation As SldWorks.Annotation
Dim swNote As SldWorks.note
Dim boolstatus As Boolean
Dim strOutput As String
Dim nRetval as Long
Sub main()
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swModelDocExt = swModel.Extension
Set
swSelMgr = swModel.SelectionManager
Stop
'
Interactively select Note1 in the open assembly
Set
swAssemNote = swSelMgr.GetSelectedObject6(1,
0)
swModel.ClearSelection2 True
'
Now activate the part document
Set
swPart = swApp.ActivateDoc2("Block.SLDPRT",
True, nRetval)
Set
swModelDocExt = swPart.Extension
Debug.Assert
0 = nRetval
swModel.ClearSelection2 True
Stop
'Interactively
select Note1 in Block.SLDPRT part document
Set
swPartNote = swSelMgr.GetSelectedObject6(1,
0)
'
Determine if the selected notes are the same note
Set
swPartNoteCorresp = swModelDocExt.GetCorresponding(swAssemNote)
If
swPartNoteCorresp Is Nothing Then
strOutput
= "Note not obtained."
Else
If
TypeOf swPartNoteCorresp Is SldWorks.note Then
Set
swAnnotation = swPartNoteCorresp.GetAnnotation
swModel.ClearSelection2 True
boolstatus
= swAnnotation.Select3(False,
Nothing)
Debug.Print
swPartNoteCorresp.GetText
'
If swAssemNoteCorresp is swAssyNote, then
'
the pointers are different but they point to the same note
If
swPartNoteCorresp.GetText = "Note1"
Then
strOutput
= "Note obtained correctly."
Else
strOutput
= "swPartNoteCorresp Is Not swAssyNote."
End
If
End
If
End
If
swModel.ClearSelection2 True
strOutput
= strOutput + vbNewLine
MsgBox
strOutput
End Sub