The GetString method prompts the user for the input of a string at the Command prompt. The PromptStringOptions object allows you to control the input entered and how the prompt message appears. The AllowSpaces property of the PromptStringOptions object controls if spaces are allowed or not at the prompt. If set to false, pressing the Spacebar terminates the input.
GetString 方法提示用户在 AutoCAD 命令提示下输入字符串。该方法接收两个参数。PromptStringOptions 对象允许控制用户输入以及怎样显示提示信息。PromptStringOptions 对象的 AllowSpaces 属性控制是否允许输入空格。如果为 False ,按空格键将中止用户输入。
The following example displays the Enter Your Name prompt, and requires that the input from the user be terminated by pressing Enter (spaces are allowed in the input string). The entered string is displayed in a message box.
以下样例显示了“输入名称”提示,并要求用户通过按 ENTER 键来终止输入(输入字符串中可以包含空格)。输入字符串值将通过一个消息框显示出来。
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("GetStringFromUser")> _
Public Sub GetStringFromUser()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim pStrOpts As PromptStringOptions = New PromptStringOptions(vbLf & _
"Enter your name: ")
pStrOpts.AllowSpaces = True
Dim pStrRes As PromptResult = acDoc.Editor.GetString(pStrOpts)
Application.ShowAlertDialog("The name entered was: " & _
pStrRes.StringResult)
End Sub
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
[CommandMethod("GetStringFromUser")]
public static void GetStringFromUser()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter your name: ");
pStrOpts.AllowSpaces = true;
PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts);
Application.ShowAlertDialog("The name entered was: " +
pStrRes.StringResult);
}