Hide Table of Contents

Deselect Marked Entity (VB.NET)

This example shows how to deselect a previously selected and marked entity.
' Preconditions:
' 1. Ensure that the file to open exists.
' 2. Open the Output window.
' 3. Run the macro.
' Postconditions:
' 1. The Base-Extrude feature is selected and
'    marked with an 8.
' 2. Examine the graphics area to verify.
' 3. Press F5 to continue.
' 4. The Base-Extrude feature is deselected.
' 5. Examine the Output window and graphics
'    area to verify.
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
    Public Sub main()
        Dim swModel As ModelDoc2
        Dim swDocSpecification As DocumentSpecification
        Dim swSelMgr As SelectionMgr
        Dim swModelExt As ModelDocExtension
        Dim bRet As Boolean
        Dim lMark As Integer
        Dim lMarkedIdx As Integer
        Dim lNumMarkedSelections As Integer
        Dim lNumAllSelections As Integer
        ' Open the document
        swDocSpecification = swApp.GetOpenDocSpec("C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\swutilities\bracket_a.sldprt")
        swModel = swApp.ActiveDoc
        If swModel Is Nothing Then
            swModel = swApp.OpenDoc7(swDocSpecification)
        End If
        swSelMgr = swModel.SelectionManager
        swModelExt = swModel.Extension
        ' Select the Base-Extrude feature and mark it with a a value of 8
        bRet = swModelExt.SelectByID2("Base-Extrude""BODYFEATURE", 0, 0, 0, False, 8, Nothing, swSelectOption_e.swSelectOptionDefault)
        ' Examine the graphics area to verify that Base-Extrude is selected
        ' Press F5 to continue
        ' Look for a given mark value
        lMark = 8
        ' Get the number of marked selections
        lNumMarkedSelections = swSelMgr.GetSelectedObjectCount2(lMark)
        Debug.Print("Number of marked selections = " & lNumMarkedSelections)
        ' Get the total number of selections
        lNumAllSelections = swSelMgr.GetSelectedObjectCount2(-1)
        Debug.Print("Number of selections        = " & lNumAllSelections)
        Debug.Print(" ")
        'Deselect the marked selection
        For lMarkedIdx = 1 To lNumAllSelections
            Debug.Print("Selected object #" & lMarkedIdx & " deselected? " & swSelMgr.DeSelect2(lMarkedIdx, lMark))
        Next lMarkedIdx
        ' Examine the graphics area to verify that Base-Extrude is deselected
    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

Subject:   Feedback on Help Topics
Page:   Deselect Marked Entity Example (VB.NET)
*   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) 2015 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.