找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1066|回复: 0

[分享] How to exit “Editor.GetSelection” on keyword selection

[复制链接]

已领礼包: 859个

财富等级: 财运亨通

发表于 2014-6-9 01:04:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
How to exit “Editor.GetSelection” on keyword selection                         By Virupaksha Aithal
One way to exit the “GetSelection” API on keyword selection is to throw an AutoCAD exception from the keyword press event handler. Below is a sample example of the procedure. On press of any keyword, below code throws the “Autodesk.AutoCAD.Runtime.ErrorStatus.OK” exception passing the keyword pressed. This exception is handled in the code to identify the keyword pressed.
[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);
}




论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-22 23:59 , Processed in 0.350601 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表