When collecting input from the user, you want to make sure you limit the type of information they can enter so you can get the desired response. The various prompt option objects are used to not only define the prompt displayed at the Command prompt, but also restrict the input that the user can provide. With some of the input methods, not only can you get a return value based on the type of method used but also get a keyword.
当让用户选择时,你可能限制用户的输入信息,使其符合你的需求。各种的提示选项对象不仅用于定义显示的命令提示,还可以限制用户的输入。有一些输入方法,不仅可以获得一个基于所用方法的类型的值,还可以获得一个关键词。
For example, you can use the GetPoint method to have the user specify a point or respond with a keyword. This is how commands like LINE, CIRCLE, and PLINE work.
例如,你可以使用 GetPoint 方法获得用户指定的点或输入的关键字。像这样的命令有LINE, CIRCLE 和 PLINE。
The following example prompts the user for a positive non-zero integer value or a keyword.
本例提示用户输入正的非零整数值或关键字。
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("GetIntegerOrKeywordFromUser")> _
Public Sub GetIntegerOrKeywordFromUser()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim pIntOpts As PromptIntegerOptions = New PromptIntegerOptions("")
pIntOpts.Message = vbCrLf & "Enter the size or "
'' 限制输入正的非负值 Restrict input to positive and non-negative values
pIntOpts.AllowZero = False
pIntOpts.AllowNegative = False
'' 定义有用的关键字并允许按回车键 Define the valid keywords and allow Enter
pIntOpts.Keywords.Add("Big")
pIntOpts.Keywords.Add("Small")
pIntOpts.Keywords.Add("Regular")
pIntOpts.Keywords.Default = "Regular"
pIntOpts.AllowNone = True
'' 获得用户输入的值 Get the value entered by the user
Dim pIntRes As PromptIntegerResult = acDoc.Editor.GetInteger(pIntOpts)
If pIntRes.Status = PromptStatus.Keyword Then
Application.ShowAlertDialog("Entered keyword: " & _
pIntRes.StringResult)
Else
Application.ShowAlertDialog("Entered value: " & _
pIntRes.Value.ToString())
End If
End Sub
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
[CommandMethod("GetIntegerOrKeywordFromUser")]
public static void GetIntegerOrKeywordFromUser()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
PromptIntegerOptions pIntOpts = new PromptIntegerOptions("");
pIntOpts.Message = "\nEnter the size or ";
// 限制输入正的非负值 Restrict input to positive and non-negative values
pIntOpts.AllowZero = false;
pIntOpts.AllowNegative = false;
// 定义有用的关键字并允许按回车键 Define the valid keywords and allow Enter
pIntOpts.Keywords.Add("Big");
pIntOpts.Keywords.Add("Small");
pIntOpts.Keywords.Add("Regular");
pIntOpts.Keywords.Default = "Regular";
pIntOpts.AllowNone = true;
// 获得用户输入的值 Get the value entered by the user
PromptIntegerResult pIntRes = acDoc.Editor.GetInteger(pIntOpts);
if (pIntRes.Status == PromptStatus.Keyword)
{
Application.ShowAlertDialog("Entered keyword: " +
pIntRes.StringResult);
}
else
{
Application.ShowAlertDialog("Entered value: " +
pIntRes.Value.ToString());
}
}