How to use Editor.SetImpliedSelection

How to use Editor.SetImpliedSelection

stefanome
Collaborator Collaborator
1,085 Views
1 Reply
Message 1 of 2

How to use Editor.SetImpliedSelection

stefanome
Collaborator
Collaborator

I have tried a few examples found on the forum and on the documentation, but I was never able to set the selection at the end of the command.

 

Below is a simple test that is supposed to keep selected only the first pre-selected entity.

 

You can test it by selecting a few entities and running the command. After the the command exits, only the first pre-selected entity should be selected. Instead nothing is selected.

 

[CommandMethod("TestRemoveItemFromPreselection", CommandFlags.UsePickSet)]
public void TestRemoveItemFromPreselection()
{
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
var selectionResult = ed.SelectImplied();
if (selectionResult.Status != PromptStatus.OK)
{
ed.WriteMessage($"selectionResult.Status: {selectionResult.Status}");
return;
}
var selectionSet = selectionResult.Value;
var ids = new ObjectIdCollection(selectionSet.GetObjectIds());
var ids2 = new ObjectId[1];
ids2[0] = ids[0];
ed.SetImpliedSelection(ids2);
}

 

0 Likes
Accepted solutions (1)
1,086 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You have to add the CommandFlags.Redraw.

 

        [CommandMethod("TestRemoveItemFromPreselection", CommandFlags.UsePickSet | CommandFlags.Redraw)]
        public void TestRemoveItemFromPreselection()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var selectionResult = ed.SelectImplied();
            if (selectionResult.Status != PromptStatus.OK)
            {
                ed.WriteMessage($"selectionResult.Status: {selectionResult.Status}");
                return;
            }
            var ids2 = new[] { selectionResult.Value.GetObjectIds()[0] };
            ed.SetImpliedSelection(ids2);
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub