Hide Table of Contents

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. Copy install_dir\samples\tutorial\api\block.sldprt to c:\temp.
' 2. Open c:\temp\block.sldprt and add a note containing the text Note1.
' 3. Save the part.
' 4. Create an assembly of the part.
' 5. Save the assembly as c:\temp\block.sldasm.
' 6. Open the Immediate window.
' Postconditions:
' 1. At Stop, select the note and press F5.
' 2. Gets the Note object in the assembly.
' 3. Activates the part document.
' 4. At Stop, select the note and press F5.
' 5. Gets the Note object in the assembly.
' 6. Gets whether the notes in the part and assembly are the same.
' 7. Examine the Immediate window.
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 status As Boolean
Dim errors As Long
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swModelDocExt = swModel.Extension
    Set swSelMgr = swModel.SelectionManager    
    ' Select Note1 and press F5    
    Set swAssemNote = swSelMgr.GetSelectedObject6(1, 0)
    swModel.ClearSelection2 True    
    ' Activate the part document
    Set swPart = swApp.ActivateDoc3("Block.SLDPRT", True, swRebuildOnActivation_e.swUserDecision, errors)
    Set swModel = swApp.ActiveDoc
    Set swModelDocExt = swPart.Extension
    swModel.ClearSelection2 True    
    ' Select Note1 and press F5    
    Set swPartNote = swSelMgr.GetSelectedObject6(1, 0)    
    ' Get whether the selected notes are the same note
    Set swPartNoteCorresp = swModelDocExt.GetCorresponding(swAssemNote)
    If swPartNoteCorresp Is Nothing Then
        Debug.Print ("Note not obtained.")
        If TypeOf swPartNoteCorresp Is SldWorks.Note Then
            Set swAnnotation = swPartNoteCorresp.GetAnnotation
            swModel.ClearSelection2 True
            status = swAnnotation.Select3(False, Nothing)
            ' If swAssemNoteCorresp is swAssyNote, then
            ' the pointers are different, but they point to the same note
            If swPartNoteCorresp.GetText = "Note1" Then
                Debug.Print ("Note obtained correctly.")
                Debug.Print ("swPartNoteCorresp Is Not swAssyNote.")
            End If
        End If
    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

Subject:   Feedback on Help Topics
Page:   Get Corresponding Note in Part Example (VBA)
*   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:


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

Web Help Content Version: API Help (English only) 2016 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.