Identifying the boundary through API

By Virupaksha Aithal

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();
 }
}

Comments

4 responses to “Identifying the boundary through API”

  1. It seems that TraceBoundary only works in SCG:
    var cucs = ed.CurrentUserCoordinateSystem;
    try
    {
    ed.CurrentUserCoordinateSystem = Matrix3d.Identity;
    collection = ed.TraceBoundary(point, true);
    }
    finally
    {
    ed.CurrentUserCoordinateSystem = cucs;
    }

  2. I mean WCS (SCG is for french) sorry.

  3. Hi,
    I have drawn Some lines in one layer. A layer name is called “SteelBoundary”
    All lines are connected. Now I want to find closest boundary only in this layer. How i can do. Some other lines also be there in other layers but I want to search only in
    “SteelBoundary” layers
    Thanks
    Parthiv

  4. SpeedCAD Avatar
    SpeedCAD

    I’ve seen this recently, and it occurs to me that you turn off all layers except the SteelBoundary layer, then apply TraceBoundary

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading