Changing the draw order of the entity

By Virupaksha Aithal

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

Comments

One response to “Changing the draw order of the entity”

  1. John Lockhart Avatar
    John Lockhart

    Wow, can’t believe some of these changes. How does this make me more productive? Are we getting away from short commands? …and replace the simple pull-down with typing out “drawing order” really? Who stayed up late dreaming up this?
    My favorite is where you changed the sequence of Change properties. Sure why not?

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading