0

Here is some simple code for asking the user to select some LINE and / or ARC entities:

_AcDb.TypedValue[] dxfs = new _AcDb.TypedValue[] 
{
    new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<or"),
    new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "LINE"),
    new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "ARC"),
    new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "or>"),
};
_AcEd.SelectionFilter sFilter = new _AcEd.SelectionFilter(dxfs);
_AcEd.PromptSelectionOptions pso = new _AcEd.PromptSelectionOptions
{
    MessageForAdding = "Select LINES and/or ARCS",
    MessageForRemoval = "Remove LINES and/or ARCS",
    AllowDuplicates = false
};

_AcEd.PromptSelectionResult res = editor.GetSelection(pso, sFilter);
if (res.Status == _AcEd.PromptStatus.OK)

Now, suppose be modify our tool so that it uses CommandFlags.UsePickSet. Now I can test for an existing selection set:

_AcEd.PromptSelectionResult res = editor.SelectImplied();

If the implied selection set result is OK, how can we easily validate that selection set against our filter? Afterall, the user might accidentally pick up a CIRCLE which we would want to ignore.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

1 Answers1

0

I can confirm that the answer here (Filter Pickfirst Selectionset) is still correct. To quote:

With CommandFlags.UsePickSet, the selection filter passed to the EditorGetSelection() method is automatically applied to the active selection if any.

I repeat the code snippet in case the link breaks:

[CommandMethod("Test", CommandFlags.UsePickSet)]
public void Test()
{
    Document doc = AcAp.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    TypedValue[] filter = { new TypedValue(0, "INSERT") };
    PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(filter));
    if (psr.Status != PromptStatus.OK) return;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        foreach (SelectedObject obj in psr.Value)
        {
            BlockReference br = (BlockReference)tr.GetObject(obj.ObjectId, OpenMode.ForWrite);
            br.Color = Color.FromColorIndex(ColorMethod.ByAci, 30);
        }
        tr.Commit();
    }
}

All we need to do is add the CommandFlags.UsePickSet and the system will take care of the rest (using your filter). Cool.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164