GetString メソッドは、コマンド プロンプトでユーザに文字列の入力を要求します。PromptStringOptions オブジェクトによって、入力された文字列とプロンプト メッセージの表示方法をコントロールすることができます。PromptStringOptions オブジェクトの AllowSpaces プロパティは、プロンプトでスペースを使用できるかどうかをコントロールします。false に設定した場合、[Spacebar]を押すと、入力は終了します。
次の例では、「あなたの名前を入力してください」というプロンプトが表示され、[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);
}
Sub GetStringFromUser()
Dim retVal As String
retVal = ThisDrawing.Utility.GetString _
(1, vbCrLf & "Enter your name: ")
MsgBox "The name entered was: " & retVal
End Sub