Create a pair of Point3D objects that define a window. P3D1 will be bottom right, and P3D2 will be top left. I use the term "aperture" - the last value I used was 20 metres. This creates a window that is 40 metres square, with your endpoint in the centre.
double aperture = 20.0;
Point3d P3D1 = new Point3d(yourpolylineendpoint.X - aperture, yourpolylineendpoint.Y - aperture, 0);
Point3d P3D2 = new Point3d(yourpolylineendpoint.X + aperture, yourpolylineendpoint.Y + aperture, 0);
Define a typedvalue and selection filter for "INSERT".
acdb.TypedValue[] values = { new acdb.TypedValue((int)acdb.DxfCode.Start, "INSERT") };
SelectionFilter sf = new SelectionFilter(values);
Create a prompt for select crossing window using your new points.
PromptSelectionResult psr = doc.Editor.SelectCrossingWindow(P3D1, P3D2, sf);
Check the status and see if there are any inserts within the window.
if (psr.Status == PromptStatus.OK && psr.Value.Count > 0)
{
acdb.ObjectIdCollection psrobjids = new acdb.ObjectIdCollection(psr.Value.GetObjectIds());
foreach (acdb.ObjectId oid in psrobjids)
{
acdb.BlockReference myblk = (acdb.BlockReference)tx.GetObject(oid, acdb.OpenMode.ForRead);
if (myblk.Name == "the block you are looking for")
{
// do what you need to do
// break;
}
}
}
<edit>
I am not sure if this way is any better than your last post. It looks like that works as well. Your way will work even if the block is not visible in the editor. I believe that object selection using window crossing implies that the object is visible in the editor window. If that's correct, your way is better.
</edit>