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. |
There are several types of location boundaries. They are all represented by descendents of the LocationBoundary class, as illustrated in the following diagram.
- Create the query using ProjectModel.CreateQuery().
- Create one or more query conditions using the constructors for DataCondition, LocationCondition, PropertyCondition, and SqlCondition.
- Create one or more query branches using the constructor for QueryBranch.
- Build the query tree by appending query conditions and branches using QueryBranch.AppendOperand().
- Create the query definition by passing the root query branch to QueryModel.Define().
- Optionally, save the query definition in an external file or query library.
- You may want to set the mode, enable or disable property alteration, or create a report template for the query.
- 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.