Each block in AutoCAD can maintain draw order information of the entities belongs to it. The draw order (DrawOrderTable) is stored as extension dictionary in the block table record. In .NET, you can access this dictionary using API “BlockTableRecord.DrawOrderTableId”. Draw order (DrawOrderTable), provides API’s like MoveToBottom, MoveToTop, MoveBelow, MoveAbove and etc to change the draw order of entities inside the block.
[CommandMethod("DrawOrderTest")]
static public void DrawOrderTest()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
string message = "nSelect a entity to move to bottom";
PromptEntityOptions options = new PromptEntityOptions(message);
PromptEntityResult acSSPrompt = ed.GetEntity(options);
if (acSSPrompt.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Entity ent = tr.GetObject(acSSPrompt.ObjectId,
OpenMode.ForRead) as Entity;
//get the block
BlockTableRecord block = tr.GetObject(ent.BlockId,
OpenMode.ForRead) as BlockTableRecord;
//get the draw oder table of the block
DrawOrderTable drawOrder =
tr.GetObject(block.DrawOrderTableId,
OpenMode.ForWrite) as DrawOrderTable;
ObjectIdCollection ids = new ObjectIdCollection();
ids.Add(acSSPrompt.ObjectId);
//move the selected entity so that entity is
//drawn in the beginning of the draw order.
drawOrder.MoveToBottom(ids);
tr.Commit();
}
}

Leave a Reply