Get All Objects Within Extents Through Database

Get All Objects Within Extents Through Database

jschierenbeck
Enthusiast Enthusiast
337 Views
1 Reply
Message 1 of 2

Get All Objects Within Extents Through Database

jschierenbeck
Enthusiast
Enthusiast

I want to be able to select all objects within a two points on a drawing (a window selection).

 

However, I want to be able to achieve this through a database and not through PromptSelectionResult, since the drawing will be closed.

 

Basically, something like this

PromptSelectionResult prRes = AcEnv.ed.SelectWindow(dwgpt1, dwgpt2);

ObjectId[] objIdArray = prRes.Value.GetObjectIds();

 

But on a closed drawing. 

 

Is this possible?

0 Likes
Accepted solutions (1)
338 Views
1 Reply
Reply (1)
Message 2 of 2

jschierenbeck
Enthusiast
Enthusiast
Accepted solution

This is a solution I found for this, but it seems like there should be an easier way.

I ended up iterating though all the objects in the drawing and comparing the extents

 

var blockTable = (BlockTable)acTrans.GetObject(database.BlockTableId, OpenMode.ForRead);

foreach (var btrId in blockTable)
{
      var btr = (BlockTableRecord)acTrans.GetObject(btrId, OpenMode.ForRead);

      if(btr.IsLayout)
      {
         foreach(var id in btr)
         {
            var ent = (Entity)acTrans.GetObject(id, OpenMode.ForRead);

         try
         {
            var ext = ent.GeometricExtents;

            if(ext.MaxPoint.X <= extents.MaxPoint.X && ext.MaxPoint.Y <= extents.MaxPoint.Y && ext.MinPoint.X >=         extents.MinPoint.X && ext.MinPoint.Y >= extents.MinPoint.Y)
            {
               foundBlocksList.Add(ent.Id);
            }
          }
         catch (Exception ex)
         {
            if (!ex.Message.Contains("eNullExtents"))
            throw;
         }
      }
   }
}

0 Likes