田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 4 48
 123456
78910111213
14151617181920
21222324252627
282930


站点统计

最新评论



AutoCAD安装错误: 请插入某驱动器 "错误1327 驱动器无效:D/“ 注册表中的AutoCAD系列ProductID和LocaleID
未知 如何通过输入关键字退出"Editor.GetSelection”   [ 日期:2014-01-18 ]   [ 来自:本站原创 ]  HTML
How to exit "Editor.GetSelection” on keyword selection

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

文章来自 http://adndevblog.typepad.com/autocad/2013/12/how-t ... ction-on-keyword-selection.html

下面是转换后的VB.Net源码:
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Public Class SELKW
    <CommandMethod("SELKW")> _
    Public Sub GetSelectionWithKeywords()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        ' Create our options object
        Dim pso As PromptSelectionOptions = New PromptSelectionOptions()
        ' Add our keywords
        pso.Keywords.Add("First")
        pso.Keywords.Add("Second")
        ' Set our prompts to include our keywords
        Dim kws As String = pso.Keywords.GetDisplayString(True)
        pso.MessageForAdding = vbLf & "Add objects to selection or " + kws
        pso.MessageForRemoval = vbLf & "Remove objects from selection or " + kws
        AddHandler pso.KeywordInput, AddressOf pso_KeywordInput
        Dim psr As PromptSelectionResult = Nothing
        Try
            psr = ed.GetSelection(pso)
            'your logic
            If psr.Status = PromptStatus.OK Then
            End If
        Catch ex As System.Exception
            If TypeOf ex Is Autodesk.AutoCAD.Runtime.Exception Then
                Dim aEs As Autodesk.AutoCAD.Runtime.Exception = TryCast(ex, Autodesk.AutoCAD.Runtime.Exception)
                'user has pressed keyword.
                If aEs.ErrorStatus = Autodesk.AutoCAD.Runtime.ErrorStatus.OK Then
                    ed.WriteMessage(vbLf & "Keyword entered: {0}", ex.Message)
                    'other exception, please handle
                Else
                End If
            End If
        End Try

    End Sub
    Private Sub pso_KeywordInput(ByVal sender As Object, ByVal e As SelectionTextInputEventArgs)
        'user has pressed keyword, so throw Exception
        Throw New Autodesk.AutoCAD.Runtime.Exception(Autodesk.AutoCAD.Runtime.ErrorStatus.OK, e.Input)
    End Sub
End Class


【如何通过输入关键字退出Editor.GetSelection.rar】点击下载此文件

[本日志由 tiancao1001 于 2014-01-18 10:40 PM 编辑]


暂时没有评论
发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:2*9=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©