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

Leave a Reply