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) 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



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 Corresponding Note in Part 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.