Editor.SelectAll with entity and layer selection filter

By Virupaksha Aithal

While using “Editor.SelectAll” API, you can provide “SelectionFilter” to filter out the unwanted entities. Below code shows a simple example which only gets the Lines and circles from a specified layer only (0, Layer1, Layer2).

[CommandMethod("LayerSelection")]
public void LayerSelection()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    TypedValue[] filterlist = new TypedValue[2];
    //select circle and line
    filterlist[0] = new TypedValue(0, "CIRCLE,LINE");
    //8 = DxfCode.LayerName
    filterlist[1] = new TypedValue(8, "0,Layer1,Layer2");
    SelectionFilter filter =
                            new SelectionFilter(filterlist);
 
    PromptSelectionResult selRes = ed.SelectAll(filter);
 
    if (selRes.Status != PromptStatus.OK)
    {
        ed.WriteMessage(
                    "nerror in getting the selectAll");
        return;
    }
    ObjectId[] ids = selRes.Value.GetObjectIds();
 
    ed.WriteMessage("No entity found: "
                           + ids.Length.ToString() + "n");
 
}

Comments

6 responses to “Editor.SelectAll with entity and layer selection filter”

  1. I’m using ed.SelectAll and ed.Getselection a lot because of the speed of these methods.
    When I debug my app with C# VS 2010 in AutoCAD 2013 the speed has reduced a lot. This is related to the number of objects in the drawing, large drawings will totally freeze my app.
    Loading my (Debug as well as Release built) app in AutoCAD without debugging in VS solves it, the speed returned again. So publishing to my customers is no problem.
    Did you notice this issue too with AutoCAD 2013?
    Greetings,

  2. I need to select graphical entities (MTexe exactly)inside a blockreference.
    can i use the blockreference instead of layer in this example?
    if no, can you help me?
    thanks

  3. Virupaksha Aithal Avatar
    Virupaksha Aithal

    Hi,
    Sorry, you cannot use SelectAll API to select the nested (entity inside the block reference). You need to use GetNestedEntity API . refer http://adndevblog.typepad.com/autocad/2012/05/modifying-contents-of-a-picked-cell-inside-a-table.html
    Thanks
    Viru

  4. I need to select polylines which contains some specific name
    What is the best way?

  5. Hi
    I want to select last 3 entities.
    Is it possible using filter?

  6. Jose Antonio mateos Avatar
    Jose Antonio mateos

    Is there any way in selecting Entities by their ObjectId’s?

Leave a Reply to OCODERCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading