Sometimes, when we use the getselection function to allow users to select objects, we may provide users with some keyword options. To receive the selected keyword options, we need to use the promptselectionoptions. keywordinput event.
However, sometimes, when you select a keyword item, you need to end the getselection master operation (This provides better experience and makes it easier for users), but you have not found a solution, after trying many methods, they all ended up failing.
Today, there is a function that needs to be implemented, so I asked in the group, the fat man said that he has a QQ space, so I went in and saw it and suddenly realized: throw an exception in the keywordinput event.
[CommandMethod("SELKW")]publicvoid GetSelectionWithKeywords(){ Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; // Create our options object PromptSelectionOptions pso = newPromptSelectionOptions(); // 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; pso.KeywordInput += newSelectionTextInputEventHandler(pso_KeywordInput); PromptSelectionResult psr = null; try { psr = ed.GetSelection(pso); if (psr.Status == PromptStatus.OK) { //your logic } } catch (System.Exception ex) { if (ex is Autodesk.AutoCAD.Runtime.Exception) { Autodesk.AutoCAD.Runtime.Exception aEs = ex as Autodesk.AutoCAD.Runtime.Exception; //user has pressed keyword. if (aEs.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.OK) { ed.WriteMessage("\nKeyword entered: {0}", ex.Message); } else { //other exception, please handle } } } }void pso_KeywordInput(object sender, SelectionTextInputEventArgs e){ //user has pressed keyword, so throw Exception throw new Autodesk.AutoCAD.Runtime.Exception( Autodesk.AutoCAD.Runtime.ErrorStatus.OK, e.Input);}