GetSelectedObject Method (ISelectionManager) Send Feedback
See Also  Example
SelObj[out]
Selected entity
SSType
Type of selection as defined in dsSelectionSetType_e
AtIndex
Index position within the current selection set, where index ranges from 0 to ISelectionManager::GetSelectedObjectCount
ObjType[out]
Selected entity as defined in dsObjectType_e; null might be returned if the selected entity is not supported of if nothing is selected
Gets the selected entity.

Syntax

Visual Basic 
Function GetSelectedObject( _
   ByVal SSType As dsSelectionSetType_e, _
   ByVal AtIndex As System.Integer, _
   ByRef ObjType As dsObjectType_e _
) As System.Object
C# 
System.object GetSelectedObject( 
   dsSelectionSetType_e SSType,
   System.int AtIndex,
   out dsObjectType_e ObjType
)
JavaScript 
GetSelectedObject( 
   SSType : String,
   AtIndex : Number
) : {
   ObjType : String,
   SelObj : dsObject
}
COM native C++ 
HRESULT GetSelectedObject( 
   dsSelectionSetType_e SSType,
   LONG AtIndex,
   dsObjectType_e* ObjType,
   IDispatch** SelObj
) 
C++ 
DSRESULT GetSelectedObject( 
   dsSelectionSetType_e SSType,
   long AtIndex,
   dsObjectType_e* ObjType,
   dsObject** SelObj
) 

Parameters

SSType
Type of selection as defined in dsSelectionSetType_e
AtIndex
Index position within the current selection set, where index ranges from 0 to ISelectionManager::GetSelectedObjectCount
ObjType[out]
Selected entity as defined in dsObjectType_e; null might be returned if the selected entity is not supported of if nothing is selected
SelObj[out] or Return Value
Selected entity

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

 

See Also

Availability

DraftSight V1R1