Can I get the list of entities which were selected before the current command started (in .NET)?

By Marat Mirgaleev

Issue

If the user had selected some entities and then started my command, can I find out which entities were selected?

Solution

Yes, it is possible, if the PICKFIRST system variable is set to 1 and your command has the UsePickSet flag set.

The sample below shows a command that prints out the list of selected entities.

[CommandMethod("LiPS", CommandFlags.UsePickSet)]      public static void ListPreSelected()      {        Document doc = Application.DocumentManager.MdiActiveDocument;        PromptSelectionResult selectionResult =                                               doc.Editor.SelectImplied();        if (selectionResult.Status == PromptStatus.OK)        {          using (Transaction tr =                       doc.Database.TransactionManager.StartTransaction())          {            SelectionSet currentlySelectedEntities =                                                    selectionResult.Value;            foreach (ObjectId id                      in currentlySelectedEntities.GetObjectIds())            {              Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;              doc.Editor.WriteMessage("n..." + ent.ToString());            }          }        }        else          doc.Editor.WriteMessage("n...SelectionResult.Status="                                     + selectionResult.Status.ToString());      } // ListPreSelected()

Comments

One response to “Can I get the list of entities which were selected before the current command started (in .NET)?”

  1. Hi, I see, this is an older post, but maybe it’s still active. Is there a way to find out, which object is involved in a certain command execution?
    Especially if the command “GRIP_POPUP” starts on a dynamic block, the current selection does not seem to help, since I can start the command even if multiple obejcts are currently selected and the command affects one Blockref only.
    Any hints are appreciated.
    Thanks,
    Daniel

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading