GetKeywords 方法
 
 

The GetKeywords method prompts the user for input of a keyword at the Command prompt. The PromptKeywordOptions object allows you to control the input entered and how the prompt message appears. The Keywords property of the PromptKeywordOptions object allows you to define keywords that can be entered at the Command prompt.

GetKeyword 方法提示用户在 AutoCAD 命令提示下输入关键字。PromptKeywordOptions 对象允许用户控制输入和如何显示提示信息。PromptKeywordOptions 对象的 Keywords 属性允许用户定义可以在命令提示中输入的关键字。

从 AutoCAD 命令行获取用户输入的关键字

The following example forces the user to enter a keyword by setting the property AllowNone to false, which disallows NULL input (pressing Enter). The Keywords property is used to add the valid keywords allowed.

以下样例通过设置 AllowNone 属性为False强制用户输入关键字,而禁止输入 NULL(按回车键)。Keywords 用于添加有效的关键字列表。

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 代码参考

A more user-friendly keyword prompt is one that provides a default value if the user presses Enter (NULL input). Notice the minor modifications to the following example.

更加易用的关键字提示可以在用户按 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 代码参考