GetKeywords メソッドは、コマンド プロンプトでユーザにキーワードの入力を要求します。PromptKeywordOptions オブジェクトでは、入力内容およびプロンプト メッセージの表示方法を制御できます。PromptKeywordOptions オブジェクトの Keywords プロパティでは、コマンド プロンプトで入力できるキーワードを定義できます。
次の例では、AllowNone プロパティを false に設定して NULL 入力([Enter]を押す)を認めないで、ユーザにキーワードの入力を要求しています。Keywords プロパティは、許可される有効なキーワードを追加するために使用されます。
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("GetKeywordFromUser")> _
Public Sub GetKeywordFromUser()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim pKeyOpts As PromptKeywordOptions = New PromptKeywordOptions("")
pKeyOpts.Message = vbLf & "Enter an option "
pKeyOpts.Keywords.Add("Line")
pKeyOpts.Keywords.Add("Circle")
pKeyOpts.Keywords.Add("Arc")
pKeyOpts.AllowNone = False
Dim pKeyRes As PromptResult = acDoc.Editor.GetKeywords(pKeyOpts)
Application.ShowAlertDialog("Entered keyword: " & _
pKeyRes.StringResult)
End Sub
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);
}
Sub GetKeywordFromUser()
Dim keyWord As String
ThisDrawing.Utility.InitializeUserInput 1, "Line Circle Arc"
keyWord = ThisDrawing.Utility.GetKeyword _
(vbCrLf & "Enter an option [Line/Circle/Arc]: ")
MsgBox keyWord, , "GetKeyword Example"
End Sub
キーワード プロンプトで、ユーザが[Enter]を押した(NULL 入力)場合に既定値が指定されるようにすると、もっと使いやすくなります。次の例では、小さな修正箇所がありますので注意してください。
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("GetKeywordFromUser2")> _
Public Sub GetKeywordFromUser2()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim pKeyOpts As PromptKeywordOptions = New PromptKeywordOptions("")
pKeyOpts.Message = vbLf & "Enter an option "
pKeyOpts.Keywords.Add("Line")
pKeyOpts.Keywords.Add("Circle")
pKeyOpts.Keywords.Add("Arc")
pKeyOpts.Keywords.Default = "Arc"
pKeyOpts.AllowNone = True
Dim pKeyRes As PromptResult = acDoc.Editor.GetKeywords(pKeyOpts)
Application.ShowAlertDialog("Entered keyword: " & _
pKeyRes.StringResult)
End Sub
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);
}
Sub GetKeywordFromUser2()
Dim keyWord As String
ThisDrawing.Utility.InitializeUserInput 0, "Line Circle Arc"
keyWord = ThisDrawing.Utility.GetKeyword _
(vbCrLf & "Enter an option [Line/Circle/Arc] <Arc>: ")
If keyWord = "" Then keyWord = "Arc"
MsgBox keyWord, , "GetKeyword Example"
End Sub