Presume you have some DWG files attached to your project in AutoCAD Map 3D and you want to run a Query with Boundary Type as 'Point'. What you do in Map 3D?
You bring up the 'Define Query of Attached Drawing(s)' dialog box and select the 'Location' button. In 'Location Condition' dialog box, select 'Point' (see the screenshot below) and define the location and finally execute the Query. You get to see the desired result in Map 3D Model space.
In a complicated project you don't want user to select the Point location arbitrarily and you simply want them to run a predefined custom command to execute the query with that particular point location. Here is a VB.NET code snippet which uses Map 3D managed API to run a custom query:
'' Create the query using ProjectModel.CreateQuery().
Dim dwg As Document = Application.DocumentManager.MdiActiveDocument
Dim database As Database = dwg.Database
Dim PROJECT As Project.ProjectModel = HostMapApplicationServices.Application.ActiveProject
Dim qryModel As QueryModel = PROJECT.CreateQuery()
'' Clear the exisitng Query
qryModel.Clear()
'' Create one or more query conditions
Dim locationCondition As Query.LocationCondition = New Query.LocationCondition
Dim qryCondition As LocationCondition = New LocationCondition()
'' This point location is specific to a test DWG file
Dim pt3d As Point3d = New Point3d(3080168.7995, 1271284.8294, 0.0)
Dim pntBdry As PointBoundary = New PointBoundary(pt3d)
qryCondition.Boundary = pntBdry
Dim qryBranch As New QueryBranch(JoinOperator.OperatorAnd)
qryBranch.AppendOperand(qryCondition)
''Create the query definition by passing the root query branch to QueryModel.Define().
qryModel.Define(qryBranch)
qryModel.Mode = QueryType.QueryDraw
qryModel.Run()
Hope this is useful to you!



Leave a Reply