Hide Table of Contents

Select All in Part, Assembly, or Drawing (VB.NET)

This example shows how to select everything in the graphics area of a part or assembly document or in the sheet of a drawing document, as if you box-selected everything in the graphics area or the sheet.

' ******************************************************************************
' Preconditions:
' 1. Part, assembly, and drawing documents opened by the macro
'    exist.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Examine:
'    * Sheet to verify that all of the entities in the drawing
'      are selected.
'    * Immediate window to see how many entities are selected.
' 2. Click Window > bolt-assembly.sldasm to switch to the assembly
'    document.
' 3. Examine:
'    * Graphics area to verify that the all of the components
'      in the assembly are selected.
'    * Immediate window to see how many components are selected.
' 4. Click Window > bolt.sldprt to switch to the part document.
' 5. Examine:
'    * Graphics area to verify that the all of the edges
'      in the part are selected.
'    * Immediate window to see how many edges are selected.
'
' NOTE: Because these documents are used elsewhere, do not save any
' changes when closing them.
' ******************************************************************************

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics

Partial Class SolidWorksMacro

    
Sub Main()

        
Dim swModel As ModelDoc2
        
Dim swModelDocExt As ModelDocExtension
        
Dim swSelMgr As SelectionMgr
        
Dim partFile As String
        Dim assemblyFile As String
        Dim drawingFile As String
        Dim errors As Integer
        Dim warnings As Integer

        ' Open a part document and select all edges in the part
        partFile = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\introsw\bolt.sldprt"
        swModel = swApp.OpenDoc6(partFile, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModelDocExt = swModel.Extension
        swSelMgr = swModel.SelectionManager
        
'Select all edges in part
        SelectAllinDocument(swModel, swModelDocExt, swSelMgr)

        
' Open an assembly document and select all components in the assembly
        assemblyFile = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\introsw\bolt-assembly.sldasm"
        swModel = swApp.OpenDoc6(assemblyFile, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModelDocExt = swModel.Extension
        swSelMgr = swModel.SelectionManager
        
'Select all components in assembly
        SelectAllinDocument(swModel, swModelDocExt, swSelMgr)

        
' Open a drawing document and select all entities in the drawing
        drawingFile = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\introsw\bolt-assembly.slddrw"
        swModel = swApp.OpenDoc6(drawingFile, swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModelDocExt = swModel.Extension
        swSelMgr = swModel.SelectionManager
        
'Select all entities in drawing
        SelectAllinDocument(swModel, swModelDocExt, swSelMgr)

    
End Sub

    Sub SelectAllinDocument(ByVal swModel As ModelDoc2, ByVal swModelDocExt As ModelDocExtension, ByVal swSelMgr As SelectionMgr)
        
Dim selCount As Integer

        ' Select all edges in a part, all components in an assembly,
        ' or all entities in a drawing
        swModelDocExt.SelectAll()

        
' Get and print the number of selections
        selCount = 0
        selCount = swSelMgr.GetSelectedObjectCount2(-1)

        
Select Case swModel.GetType
            
Case swDocumentTypes_e.swDocPART
                Debug.Print(
"Number of edges selected in part          = " & selCount)
            
Case swDocumentTypes_e.swDocASSEMBLY
                Debug.Print(
"Number of components selected in assembly = " & selCount)
            
Case swDocumentTypes_e.swDocDRAWING
                Debug.Print(
"Number of entities selected in drawing    = " & selCount)
            
Case Else
                Debug.Print("Unknown type of document.")
        
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:   Select All in Part, Assembly, or Drawing (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) 2014 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.