Hide Table of Contents
GetSelectedObjectCount Method (ISelectionManager)
SelCount[out]
Number of selected entities

Gets the number of selected entities in the current selection set.

.NET Syntax

Visual Basic (Declaration) 
Function GetSelectedObjectCount( _
   dsSelectionSetType_e SSType As dsSelectionSetType_e _
) As System.Integer
C# 
System.int GetSelectedObjectCount( 
   dsSelectionSetType_e SSType
)
JavaScript 
GetSelectedObjectCount( 
   SSType : String
) : Number
COM native C++ 
HRESULT GetSelectedObjectCount( 
   dsSelectionSetType_e SSType,
   LONG* SelCount
) 
C++ 
DSRESULT GetSelectedObjectCount( 
   dsSelectionSetType_e SSType,
   long* SelCount
) 

Parameters

SSType
Type of selection as defined in dsSelectionSetType_e
SelCount[out] or Return Value
Number of selected entities

Example

This code snippet shows how to write the names, captions, and values of the selected objects to a file.

COM native C++

        long selCount = dsSelManager->GetSelectedObjectCount( dsSelectionSetType_Current );
        strPrint.Format( L"Selected objects: (%d):\r\n", selCount );
        fileOutput.WriteString( strPrint );

        if( selCount > 0 )
        {
            for( long i = 0; i < selCount; ++i )
            {
                //Get selected object type
                dsObjectType_e retObjType;
                IDispatchPtr selObj = dsSelManager->GetSelectedObject( dsSelectionSetType_Current, i, &retObjType );

                //If selected object is Block instance
                if( dsBlockInstanceType == retObjType )
                {
                    IBlockInstancePtr blkIns( selObj );
                   
                    //Get Block definition name and write it to output file
                    bstr_t blockName = blkIns->GetBlockDefinition()->GetName();
                    strPrint.Format( L"Instance of (%s) block definition\r\n", blockName.operator const wchar_t*() );
                    fileOutput.WriteString( strPrint );                   
                }
                else
                    //If selected object is BlockAttribute definition
                    if( dsAttributeDefinitionType == retObjType )
                    {
                        IAttributeDefinitionPtr AttDefs( selObj );

                        //Get BlockAttribute definition name
                        bstr_t AttDefName = AttDefs->GetName();

                        strPrint.Format( L"Attribute definition (%s) \r\n", AttDefName.operator const wchar_t*() );
                        fileOutput.WriteString( strPrint );

                        //Get BlockAttribute definition caption
                        bstr_t AttDefCaption = AttDefs->GetCaption();

                        strPrint.Format( L"\tCaption: %s\r\n", AttDefCaption.operator const wchar_t*() );
                        fileOutput.WriteString( strPrint );

                        strPrint.Format( L"\tName: %s\r\n", AttDefName.operator const wchar_t*() );
                        fileOutput.WriteString( strPrint );
                       
                        //Get BlockAttribute definition value
                        bstr_t AttDefValue = AttDefs->GetValue();

                        strPrint.Format( L"\tValue: %s\r\n", AttDefValue.operator const wchar_t*() );
                        fileOutput.WriteString( strPrint );                       
                    }

Example

Remarks

You can also use this method to determine if a valid selection was made.
 

See Also

Availability

DraftSight V1R1


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:   GetSelectedObjectCount Method (ISelectionManager)
*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) 2021 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.