Queries

AutoCAD Map 3D .NET API

 
Queries
 
 
 

A query is a tree structure containing branches (QueryBranch objects) and conditions (DataCondition, LocationCondition, PropertyCondition, and SqlCondition objects). All of these objects are subclassed from QueryUnit.

To create a query, call ProjectModel.CreateQuery().

query = activeProj.CreateQuery()

This returns an empty QueryModel object.

A simple query can have a root branch with a single condition. More complex queries combine branches and conditions.

The criteria that the query uses to select objects are expressed in query conditions. There are four types of query conditions.

  Description
Location Conditions Based on the location of objects relative to a boundary. There are several boundary types. See Location Boundaries below.
Property Conditions Based on a particular AutoCAD property.
Data Conditions Based on object data. To query object data set the query type to DataIrd. To query object classes set the query type to DataFeature.
SQL Conditions Based on data about drawing objects that is stored in external database tables and is specified by the WHERE clause of a SQL query.

Location Boundaries

There are several types of location boundaries. They are all represented by descendents of the LocationBoundary class, as illustrated in the following diagram.

Executing Queries

To build a query

  1. Create the query using ProjectModel.CreateQuery().
  2. Create one or more query conditions using the constructors for DataCondition, LocationCondition, PropertyCondition, and SqlCondition.
  3. Create one or more query branches using the constructor for QueryBranch.
  4. Build the query tree by appending query conditions and branches using QueryBranch.AppendOperand().
  5. Create the query definition by passing the root query branch to QueryModel.Define().
  6. Optionally, save the query definition in an external file or query library.

To execute a query

  1. You may want to set the mode, enable or disable property alteration, or create a report template for the query.
  2. Call QueryModel.Run() to execute the query against all attached drawings. Call QueryModel.Execute() to execute the query for a particular drawing set.

The query mode determines if the objects from the attached drawings are displayed as a preview or cloned into the project drawing. QueryModel.Execute() returns a list of objects that have been queried in.