该方法在命令提示符下提示用户输入关键字。该对象允许您控制输入的输入以及提示消息的显示方式。该对象的属性允许您定义可在命令提示符下输入的关键字。GetKeywordsPromptKeywordOptionsKeywordsPromptKeywordOptions 注意:下划线字符 (“_”) 具有特殊含义,不能用作关键字或关键字的一部分。
在命令行中从用户获取关键字下面的示例通过将属性设置为 false 来强制用户输入关键字,这将不允许输入(按 Enter)。该属性用于添加允许的有效关键字。AllowNoneNULLKeywords VB.NETImports 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
C#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);
}
VBA/ActiveX 代码参考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 VB.NETImports 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
C#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);
}
VBA/ActiveX 代码参考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
相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 17:09
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.