Hide Table of Contents

Compare Selected Objects and Their Persistent Reference IDs (VB.NET)

This example shows how to determine if two selected entities are the same entities and if those entities have the same persistent IDs.

Using IModelDocExtension::IsSamePersistentID and ISldWorks::IsSame might be helpful when your application is passed two entities that it didn't select, and your application needs to know if they're the same entity.

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

' Preconditions: A part document is open and two

' different entities (e.g., faces, edges, vertices, etc.)

' are selected.

'

' Postconditions: None

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

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System

Imports System.Diagnostics

 

Partial Class SolidWorksMacro

 

    Public Sub main()

 

        Dim swModel As ModelDoc2

        Dim swSelMgr As SelectionMgr

        Dim swModelDocExt As ModelDocExtension

        Dim selObj1 As Object

        Dim selObj2 As Object

        Dim selObjPID1 As Object

        Dim selObjPID2 As Object

 

        swModel = swApp.ActiveDoc

        swSelMgr = swModel.SelectionManager

        swModelDocExt = swModel.Extension

 

        ' Get the selected objects

        selObj1 = swSelMgr.GetSelectedObject6(1, -1)

        selObj2 = swSelMgr.GetSelectedObject6(2, -1)

 

        Debug.Print("Compare the selected objects:")

        Select Case swApp.IsSame(selObj1, selObj2)

            Case 0

                Debug.Print("  Selected objects are not the same.")

            Case 1

                Debug.Print("  Selected objects are the same.")

            Case -1

                Debug.Print("  Unable to determine if selected objects are the same.")

        End Select

 

        Debug.Print("")

 

        Debug.Print("Compare the same objects:")

        Select Case swApp.IsSame(selObj1, selObj1)

            Case 0

                Debug.Print("  Selected objects are not the same.")

            Case 1

                Debug.Print("  Selected objects are the same.")

            Case -1

                Debug.Print("  Unable to determine if selected objects are the same.")

        End Select

 

        Debug.Print("")

 

        ' Get the persistent reference IDs of the

        ' selected objects

        selObjPID1 = swModelDocExt.GetPersistReference3(selObj1)

        selObjPID2 = swModelDocExt.GetPersistReference3(selObj2)

 

        Debug.Print("Compare the persistent reference IDs of the selected objects:")

        Select Case swModelDocExt.IsSamePersistentID(selObjPID1, selObjPID2)

            Case 0

                Debug.Print("  Selected objects do not have the same persistent reference ID.")

            Case 1

                Debug.Print("  Selected objects do have the same persistent reference ID.")

            Case -1

                Debug.Print("  Unable to determine if the selected objects have the same persistent reference ID.")

        End Select

 

        Debug.Print("")

 

        Debug.Print("Compare the persistent reference IDs of the same objects:")

        Select Case swModelDocExt.IsSamePersistentID(selObjPID1, selObjPID1)

            Case 0

                Debug.Print("  Selected objects do not have the same persistent reference ID.")

            Case 1

                Debug.Print("  Selected objects do have the same persistent reference ID.")

            Case -1

                Debug.Print("  Unable to determine if the selected objects have the same persistent reference ID.")

        End Select

 

    End Sub

 

    ''' <summary>

    ''' The SldWorks swApp variable is pre-assigned for you.

    ''' </summary>

    Public swApp As SldWorks

 

End Class



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:   Compare Selected Objects and Their Persistent Reference IDs Example (VB.NET)
*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.