码迷,mamicode.com
首页 > 其他好文 > 详细

用keyword实现Editor.GetSelection的退出功能

时间:2014-06-27 12:54:02      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   code   tar   

有时候我们在使用GetSelection功能让用户选择实体时,可能会给用户提供一些keyword选项,要接收用户选择的keyword选项,需要用到PromptSelectionOptions.KeywordInput事件。

但是,有时为了有时在用户选择了某个keyword项时,需要结束GetSelection主操作(这样体验性更好,用户更方便),但是一直没有找到解决的办法,试了好多方法都以失败告终。

今天,有一个功能又需要实现这一点,于是在群里问了一句,胖子说他QQ空间里有,于是进去一看,晃然大悟:在keywordInput事件里抛出一个异常即可。

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

 

用keyword实现Editor.GetSelection的退出功能,布布扣,bubuko.com

用keyword实现Editor.GetSelection的退出功能

标签:des   style   class   blog   code   tar   

原文地址:http://www.cnblogs.com/bomb12138/p/3810650.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!