CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

获取关键字方法 (.NET)

2023-1-1 15:32| 发布者: admin| 查看: 901| 评论: 0|来自: AutoCAD

该方法提示用户在命令提示符下输入关键字。该对象允许您控制输入的输入以及提示消息的显示方式。对象的属性允许您定义可以在命令提示符下输入的关键字。GetKeywordsPromptKeywordOptionsKeywordsPromptKeywordOptions

注意:下划线字符 (“_”) 具有特殊含义,不能用作关键字或关键字的一部分。

在命令行从用户那里获取关键字

下面的示例通过将属性设置为 false 来强制用户输入关键字,这将不允许输入(按 Enter 键)。该属性用于添加允许的有效关键字。AllowNoneNULLKeywords

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
 
<CommandMethod("GetKeywordFromUser")> _
Public Sub GetKeywordFromUser()
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

    Dim pKeyOpts As PromptKeywordOptions = New PromptKeywordOptions("")
    pKeyOpts.Message = vbLf & "Enter an option "
    pKeyOpts.Keywords.Add("Line")
    pKeyOpts.Keywords.Add("Circle")
    pKeyOpts.Keywords.Add("Arc")
    pKeyOpts.AllowNone = False

    Dim pKeyRes As PromptResult = acDoc.Editor.GetKeywords(pKeyOpts)

    Application.ShowAlertDialog("Entered keyword: " & _
                                pKeyRes.StringResult)
End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
 
[CommandMethod("GetKeywordFromUser")]
public static void GetKeywordFromUser()
{
    Document acDoc = Application.DocumentManager.MdiActiveDocument;

    PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("");
    pKeyOpts.Message = "\nEnter an option ";
    pKeyOpts.Keywords.Add("Line");
    pKeyOpts.Keywords.Add("Circle");
    pKeyOpts.Keywords.Add("Arc");
    pKeyOpts.AllowNone = false;

    PromptResult pKeyRes = acDoc.Editor.GetKeywords(pKeyOpts);

    Application.ShowAlertDialog("Entered keyword: " +
                                pKeyRes.StringResult);
}

VBA/ActiveX 代码参考

Sub GetKeywordFromUser()
    Dim keyWord As String
    ThisDrawing.Utility.InitializeUserInput 1, "Line Circle Arc"
    keyWord = ThisDrawing.Utility.GetKeyword _
              (vbCrLf & "Enter an option [Line/Circle/Arc]: ")
    MsgBox keyWord, , "GetKeyword Example"
End Sub

更用户友好的关键字提示是在用户按 Enter (输入) 时提供默认值的提示。请注意对以下示例的细微修改。NULL

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("GetKeywordFromUser2")> _
Public Sub GetKeywordFromUser2()
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

    Dim pKeyOpts As PromptKeywordOptions = New PromptKeywordOptions("")
    pKeyOpts.Message = vbLf & "Enter an option "
    pKeyOpts.Keywords.Add("Line")
    pKeyOpts.Keywords.Add("Circle")
    pKeyOpts.Keywords.Add("Arc")
    pKeyOpts.Keywords.Default = "Arc"
    pKeyOpts.AllowNone = True

    Dim pKeyRes As PromptResult = acDoc.Editor.GetKeywords(pKeyOpts)

    Application.ShowAlertDialog("Entered keyword: " & _
                                pKeyRes.StringResult)
End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
 
[CommandMethod("GetKeywordFromUser2")]
public static void GetKeywordFromUser2()
{
    Document acDoc = Application.DocumentManager.MdiActiveDocument;

    PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("");
    pKeyOpts.Message = "\nEnter an option ";
    pKeyOpts.Keywords.Add("Line");
    pKeyOpts.Keywords.Add("Circle");
    pKeyOpts.Keywords.Add("Arc");
    pKeyOpts.Keywords.Default = "Arc";
    pKeyOpts.AllowNone = true;

    PromptResult pKeyRes = acDoc.Editor.GetKeywords(pKeyOpts);

    Application.ShowAlertDialog("Entered keyword: " +
                                pKeyRes.StringResult);
}

VBA/ActiveX 代码参考

Sub GetKeywordFromUser2()
    Dim keyWord As String
    ThisDrawing.Utility.InitializeUserInput 0, "Line Circle Arc"
    keyWord = ThisDrawing.Utility.GetKeyword _
              (vbCrLf & "Enter an option [Line/Circle/Arc] <Arc>: ")
    If keyWord = "" Then keyWord = "Arc"
    MsgBox keyWord, , "GetKeyword Example"
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:20

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部