Hide Table of Contents

Get Corresponding Note in Assembly Example (VBA)

This example shows how to determine if the selected note in an assembly corresponds to the selected note in a part that is a component of the assembly.

 

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

'

' Preconditions:

'         (1) An assembly document named BlockSpherePyramid.SLDASM is open.

'         (2) Note1 exists and belongs to the part document named

'             Block.SLDPRT, which also exists and is a component of

'             BlockSpherePyramid.SDLASM.

'         (3) Block.SLDPRT has a Note1 note.

'

' Postconditions: None

'

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

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swAssembly As SldWorks.AssemblyDoc

Dim swPart As SldWorks.PartDoc

Dim swModel As SldWorks.ModelDoc2

Dim swCompModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swModelDocExt As SldWorks.ModelDocExtension

Dim swCompModelDocExt As SldWorks.ModelDocExtension

Dim swAnnotation As SldWorks.Annotation

Dim swAssemComp As SldWorks.Component2

Dim swAssemNoteCorresp As SldWorks.note

Dim swAssyNote As SldWorks.note

Dim swPartNote As SldWorks.note

Dim boolstatus As Boolean

Dim nRetVal As Long

 

Sub main()

 

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swAssembly = swModel

    Set swSelMgr = swModel.SelectionManager

    

    Stop

    ' Interactively select the note in the assembly,

    ' then programatically get the note

    Set swAssyNote = swSelMgr.GetSelectedObject6(1, 0)

    

    swModel.ClearSelection2 True

    Set swAnnotation = swAssyNote.GetAnnotation

    boolstatus = swAnnotation.Select3(False, Nothing)

 

    ' Activate the part document

    Set swPart = swApp.ActivateDoc2("Block.SLDPRT", True, nRetVal)

    Set swModelDocExt = swModel.Extension

    Set swSelMgr = swModel.SelectionManager

    Debug.Assert 0 = nRetVal

    

    swModel.ClearSelection2 True

    'Select the note in the block

  

    Stop

    ' Interactively select the note in the block

    ' then programatically get the note

    Set swPartNote = swSelMgr.GetSelectedObject6(1, 0)

        

    swModel.ClearSelection2 True

    Set swAnnotation = swPartNote.GetAnnotation

    boolstatus = swAnnotation.Select3(False, Nothing)

 

    ' Re-activate the assembly

    Set swAssembly = swApp.ActivateDoc2("BlockSpherePyramid.SLDASM", True, nRetVal)

    Debug.Assert 0 = nRetVal

    Set swModelDocExt = swModel.Extension

    Set swSelMgr = swModel.SelectionManager

    

    swModel.ClearSelection2 True

    

    ' Select the Block component in the assembly

    boolstatus = swModelDocExt.SelectByID2("Block-1@BlockSpherePyramid", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

    Set swAssemComp = swSelMgr.GetSelectedObject6(1, 0)

    Set swCompModel = swAssemComp.GetModelDoc

    Set swCompModelDocExt = swCompModel.Extension

    

    swModel.ClearSelection2 True

 

    ' Determine if the selected notes are the same note

    Set swAssemNoteCorresp = swCompModelDocExt.GetCorresponding(swPartNote)

    

    Dim strOutput As String

    ' Test feature returned by swCompMondelDocExt::GetCorrespondingEntity

    If swAssemNoteCorresp Is Nothing Then

        strOutput = "Note not obtained."

    Else

        If TypeOf swAssemNoteCorresp Is SldWorks.note Then

            Set swAnnotation = swAssemNoteCorresp.GetAnnotation

            boolstatus = swAnnotation.Select3(False, Nothing)

            Debug.Print swAssemNoteCorresp.GetText

            

            'If swAssemNoteCorresp Is swAssyNote then

            'the pointers are different, but they point to the same note

            If swAssemNoteCorresp.GetText = "Note1" Then

                strOutput = "Note obtained correctly."

            Else

                strOutput = "swAssemNoteCorresp Is not swAssyNote."

            End If

        End If

    End If

 

    strOutput = strOutput + vbNewLine

        

    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 Assembly 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.