Query Sample Code

AutoCAD Map 3D ObjectARX

 
Query Sample Code
 
 
 
    
AcMapProject *pProj = NULL;
    
// Create a new branch object
AcMapQueryBranch *pRootBranch = NULL;
pRootBranch = new AcMapQueryBranch(AcMap::kOperatorOr);
    
// Create a new property condition
const char *pcValuePC = "Layer1";
AcMapPropertyCondition *pPropertyCondition = NULL;
pPropertyCondition = new AcMapPropertyCondition(
AcMap::kOperatorOr,
AcMap::kLayer,
AcMap::kCondEq,
pcValuePC
);
    
AcMapSession *pMapSession = NULL;
AcMapQuery *pNewQuery = NULL;
    
// Get the session object
pMapSession = AcMapGetSession();
if (pMapSession)
{
// Get the currently active project 
if (pMapSession->GetProject(pProj) == AcMap::kOk)
{
// Create a new query object 
if ( pProj->CreateQuery(
pNewQuery, 
Adesk::kFalse) == AcMap::kOk )
{
// Create a new property condition 
const char *pcValuePC = "Layer1"; 
AcMapPropertyCondition *pPropertyCondition = NULL; 
pPropertyCondition = new AcMapPropertyCondition(
AcMap::kOperatorOr, 
AcMap::kLayer, 
AcMap::kCondEq, 
pcValuePC 
); 
          
// Create a new branch object 
AcMapQueryBranch *pBranch = NULL; 
pBranch = new AcMapQueryBranch();
          
// Append the condition to the branch
pBranch->AppendOperand(pPropertyCondition);
          
// Define the branch in the query
if (pNewQuery->Define(pBranch) == AcMap::kOk)
{
// Run the query. 
pNewQuery->Run();
}
// Clean up 
delete pPropertyCondition; 
delete pBranch; 
delete pNewQuery;
} // if (pProj->CreateQuery
} // if (pMapSession->GetProject
} // if (pMapSession)