GetKeywords メソッドは、コマンド プロンプトでユーザーにキーワードの入力を要求します。PromptKeywordOptions オブジェクトでは、入力内容およびプロンプト メッセージの表示方法をコントロールできます。PromptKeywordOptions オブジェクトの Keywords プロパティでは、コマンド プロンプトで入力できるキーワードを定義できます。
次の例では、AllowNone プロパティを false に設定し、NULL 入力([Enter]を押す)を許可しない状態にして、ユーザーにキーワードの入力を要求しています。Keywords プロパティは、許可される有効なキーワードを追加するために使用されます。
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);
}
キーワード プロンプトで、ユーザーが[Enter]を押した(NULL 入力)場合に既定値が指定されるようにすると、さらに使いやすくなります。次の例では、小さな修正箇所がありますので注意してください。
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);
}