AcMapQuery class

Land Desktop Development ARX CPP SDK

 

AcMapQuery class

Header file: MapArxApi.h.

Note  This class has new functions added for AutoCAD Map 3D 2005.

An instance of the AcMapQuery class represents a defined query.

Do not subclass from this class.

Creating a Query

The AcMapQuery class does not have a constructor, and you cannot create and modify its objects directly. After you have created the query definition, instantiate an AcMapQuery object using the AcMapProject::CreateQuery function. This creates the query object in the project, making the query available to the application. You are responsible for deleting the query, as shown in the following example.

// For simplicity, error checking is not shown.

#include "StdAfx.h"
#include "StdArx.h"
#include <MapArxApi.h>
#include <MapProj.h>
#include <MapQuery.h>
 
AcMapSession *mapApi = NULL;
AcMapProject *pProj = NULL;
AcMapQuery *pQuery = NULL;
 
mapApi = AcMapGetSession();
mapApi->GetProject(pProj);
pProj->CreateQuery(pQuery, Adesk::kTrue);
// define and execute the query -- code not shown
delete pQuery;

Defining a Query

A = 4) BSPSPopupOnMouseOver(event);;">query definition is built from an AcMapQueryBranch object, which describes the conditions that form the selection criteria of the query. Create the query branch and pass it to the AcMapQuery::Define function to create a query definition. See AcMapQueryBranch class for information about creating the query branch.

Modifying a Query

To modify an existing query, create a new query branch. Then call AcMapQuery::Define to redefine the query using the new query branch.

Executing a Query

Before executing a query, you may also want to set the mode (using AcMapQuery::SetMode), enable or disable = 4) BSPSPopupOnMouseOver(event);;">property alteration (using AcMapQuery::EnablePropertyAlteration) or create a report template (using AcMapQuery::GetReportTemplate) for the query. before executing a query. Then call AcMapQuery::Run to execute the query.

The following example, which assumes drawings are attached, shows how to create a command that creates, defines, and executes a query. For simplicity, error checking is not shown.

#include "StdAfx.h"
#include "StdArx.h"
#include <MapArxApi.h>
#include <MapProj.h>
#include <MapQuery.h>
#include <MapBoundary.h>
 
void asdkhelpqueryall()
{
AcMapSession    *mapApi = NULL;
AcMapProject    *pProj = NULL;
AcMapDrawingSet *pDSet = NULL;
AcMapQueryBranch *pQBranch = NULL;
AcMapLocationCondition *pLocationCondition = NULL;
AcMapQuery *pNewQuery = NULL;
 
mapApi = AcMapGetSession();
mapApi->GetProject(pProj);
pProj->GetDrawingSet(pDSet);
pQBranch = new AcMapQueryBranch(); 
pLocationCondition = new AcMapLocationCondition(AcMap::kOperatorAnd,
   AcMap::kLocationInside); 
pLocationCondition->SetBoundary((&AcMapAllBoundary;()));
pProj->CreateQuery(pNewQuery, Adesk::kFalse);
pNewQuery->Clear(Adesk::kTrue);
pNewQuery->SetMode(AcMap::kQueryDraw);
pQBranch->AppendOperand(pLocationCondition);
pNewQuery->Define(pQBranch);
pNewQuery->Run();
pDSet->ZoomExtents(); 
delete pLocationCondition;
delete pQBranch;
delete pNewQuery;
acedRetVoid();
}

Error Codes

If the return value of a query function is of type AcMap::EErrCode and the function succeeds, it returns AcMap::kOk. Error codes denoting unsuccessful conditions are listed under AcMap::EErrorCode.