using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace MyApplication
{
public class Commands
{
[CommandMethod("SELKW")]
public void GetSelectionWithKeywords()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
// Create our options object
PromptSelectionOptions pso =
new PromptSelectionOptions();
// Add our keywords
pso.Keywords.Add("FIrst");
pso.Keywords.Add("Second");
// Set our prompts to include our keywords
string kws = pso.Keywords.GetDisplayString(true);
pso.MessageForAdding =
"\nAdd objects to selection or " + kws;
pso.MessageForRemoval =
"\nRemove objects from selection or " + kws;
// Implement a callback for when keywords are entered
pso.KeywordInput +=
delegate(object sender, SelectionTextInputEventArgs e)
{
ed.WriteMessage("\nKeyword entered: {0}", e.Input);
};
// Finally run the selection and show any results
PromptSelectionResult psr =
ed.GetSelection(pso);
if (psr.Status == PromptStatus.OK)
{
ed.WriteMessage(
"\n{0} object{1} selected.",
psr.Value.Count,
psr.Value.Count == 1 ? "" : "s"
);
}
}
}
}