Use keyword to exit editor. getselection

Source: Internet
Author: User

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);}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.