AutoCAD 2011 introduced a new API to identify the boundary objects for a provided point. Below code shows the use of the same API in .NET. The equivalent ObjectARX API is “acedTraceBoundary”.
Note, only visible entities are considered while identifying the boundary objects.
[CommandMethod("BoundaryTest")]
public static void BoundaryTest()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointOptions ptOptions =
new PromptPointOptions("Select point ");
ptOptions.AllowNone = false;
PromptPointResult ptResult = ed.GetPoint(ptOptions);
if (ptResult.Status != PromptStatus.OK)
return;
DBObjectCollection collection =
ed.TraceBoundary(ptResult.Value, true);
using (Transaction Tx =
db.TransactionManager.StartTransaction())
{
ObjectId ModelSpaceId =
SymbolUtilityServices.GetBlockModelSpaceId(db);
BlockTableRecord model = Tx.GetObject(ModelSpaceId,
OpenMode.ForWrite) as BlockTableRecord;
foreach (DBObject obj in collection)
{
Entity ent = obj as Entity;
if (ent != null)
{
//make the color as red.
ent.ColorIndex = 1;
model.AppendEntity(ent);
Tx.AddNewlyCreatedDBObject(ent, true);
}
}
Tx.Commit();
}
}