GetString メソッド(.NET)

GetString メソッドは、コマンド プロンプトでユーザに文字列の入力を要求します。PromptStringOptions オブジェクトによって、入力された文字列とプロンプト メッセージの表示方法をコントロールすることができます。PromptStringOptions オブジェクトの AllowSpaces プロパティは、プロンプトでスペースを使用できるかどうかをコントロールします。false に設定した場合、[Spacebar]を押すと、入力は終了します。

コマンド ラインでユーザから文字列値を取得する

次の例では、「あなたの名前を入力してください」というプロンプトが表示され、[Enter]を押すとユーザからの入力が終了します(入力文字列内にスペースを使用することができます)。入力された文字列は、メッセージ ボックスに表示されます。

C# の例

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);
}