Share
 
 

About Requesting a Keyword (ActiveX)

The GetKeyword method prompts the user for input of a keyword at the AutoCAD Command prompt.

This method accepts only one parameter, which is the prompt string. The keywords and input parameters are defined with a call to the InitializeUserInput method.

Get a keyword from the user at the AutoCAD Command prompt

The following example forces the user to enter a keyword by setting the first parameter of InitializeUserInput to 1, which disallows NULL input (pressing Enter). The second parameter establishes the list of valid keywords.

AutoLISP
(vl-load-com)
(defun c:Ch3_KeyWord()
    (setq acadObj (vlax-get-acad-object)
          doc (vla-get-ActiveDocument acadObj)
          utilityObj (vla-get-Utility doc))

    (vla-InitializeUserInput utilityObj 1 "Line Circle Arc")
    (setq keyWord (vla-GetKeyword utilityObj "\nEnter an option [Line/Circle/Arc]: "))
    (alert (strcat "Keyword: " keyWord))
)
VBA (AutoCAD Only)
Sub Ch3_KeyWord()
  Dim keyWord As String
  ThisDrawing.Utility.InitializeUserInput 1, "Line Circle Arc"
  keyWord = ThisDrawing.Utility.GetKeyword(vbCrLf & "Enter an option [Line/Circle/Arc]: ")
  MsgBox "Keyword: " & keyWord, , "GetKeyword Example"
End Sub

A more user-friendly keyword prompt is one that provides a default value if the user presses Enter (NULL input). Notice the minor modifications to the following example:

AutoLISP
(vl-load-com)
(defun c:Ch3_KeyWord2()
    (setq acadObj (vlax-get-acad-object)
          doc (vla-get-ActiveDocument acadObj)
          utilityObj (vla-get-Utility doc))

    (vla-InitializeUserInput utilityObj 0 "Line Circle Arc")
    (setq keyWord (vla-GetKeyword utilityObj "\nEnter an option [Line/Circle/Arc] <Arc>: "))
    (if (= keyWord "")(setq keyWord "Arc"))
    (alert (strcat "Keyword: " keyWord))
)
VBA (AutoCAD Only)
Sub Ch3_KeyWord2()
  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: " & keyWord, , "GetKeyword Example"
End Sub

Was this information helpful?