DisplayManagement.Element has two properties to describe the data source for the element:
- AcquisitionCriteriaString
- AcquisitionCriteria
AcquisitionCriteriaString contains a string representation of the data source, as described in the following table:
| Element type | AcquisitionCriteriaString value |
|---|---|
| LayerElement | AutoCAD layer name |
| FeatureElement | Object classification class name |
| TopologyElement | Topology name |
| AttachedDwgsQueryElement | |
| TopologyQueryElement |
AcquisitionCriteria is of type DisplayManagement.DataSourceDescriptor. It contains additional data about the source. Each element type has a corresponding data source descriptor type, subclassed from DataSourceDescriptor. For example, the AcquisitionCriteria property for a LayerElement is of type LayerDataSourceDescriptor.
For LayerElement, FeatureElement, and TopologyElement, AcquisitionCriteria.AcquisitionStatement is the same as AcquisitionCriteriaString. AttachedDwgsQueryDataSourceDescriptor and TopologyQueryDataSourceDescriptor define additional methods and properties, as described in the following table.
| Method or property | Description |
|---|---|
| GetDrawingList() | Gets the list of attached drawings used in the query |
| SetDrawingList() | Sets the list of attached drawings used in the query |
| Query | A result buffer containing the query definition, from the QueryModel.FileOut property |
| TopologyName | For TopologyQueryDataSourceDescriptor only, the topology name used in the query |
To add a new element, create the element and its associated data source descriptor, then add it to the map. The following example adds a LayerElement that references an AutoCAD layer named “Layer1”. For other element types, create the appropriate data source descriptor.
Dim activeProject As Project.ProjectModel = _
HostMapApplicationServices.Application.ActiveProject
Dim docs As DocumentCollection = Application.DocumentManager
Dim activeDoc As Document = docs.MdiActiveDocument
Dim trans As Transaction = Nothing
Try
trans = activeDoc.TransactionManager.StartTransaction()
' Get the Object Id for the current Map
Dim managerId As ObjectId
managerId = _
DisplayManager.Create(activeProject).MapManagerId( _
activeProject, True)
Dim manager As MapManager = trans.GetObject(managerId, _
OpenMode.ForRead)
Dim currentMapId = manager.CurrentMapId
Dim currentMap As Map = trans.GetObject(currentMapId, _
OpenMode.ForWrite)
' Create the Layer element and set its
name
Dim element As LayerElement = LayerElement.Create()
element.Name = "NewLayer"
' Create the Layer Descriptor
Dim descriptor As LayerDataSourceDescriptor = Nothing
descriptor = LayerDataSourceDescriptor.Create()
descriptor.AcquisitionStatement = "Layer1"
' Now Add the new element to the current
Map
Dim iterator As IEnumerator = _
currentMap.NewIterator(True, True)
Dim elementId As ObjectId = _
currentMap.AddItem(element, iterator)
trans.AddNewlyCreatedDBObject(element, True)
element = trans.GetObject(elementId, OpenMode.ForWrite)
element.AcquisitionCriteria = descriptor
trans.Commit()
trans = Nothing
Catch e As Autodesk.AutoCAD.Runtime.Exception
' Handle exception
Finally
If Not trans Is Nothing Then
trans.Abort()
trans = Nothing
End If
End Try