概要 - ユーザ入力をコントロールする(ActiveX)

InitializeUserInput メソッドを使用すると、キーワードを定義したり、ユーザ入力メソッドへ入力するタイプを制限することができます。

このメソッドの使用法とパラメータ値は AutoLISP initget 関数とよく似ています。InitializeUserInput メソッドは、次のメソッドを合わせて使用することができます。GetAngleGetCornerGetDistanceGetIntegerGetKeywordGetOrientationGetPointGetRealInitializeUserInputGetString メソッドと一緒に使用することはできません。ユーザ入力メソッドが文字列値を返さないときは、GetInput メソッドを使用して文字列値(キーワードまたは任意の入力)を取得します。

InitializeUserInput メソッドは、2 つのパラメータを受け取ります。最初のパラメータはビット コード化された整数値で、ユーザ入力メソッドの入力オプションを決定します。2 番目のパラメータは、有効なキーワードを定義する文字列です。

AutoCAD のコマンド プロンプトでユーザから整数値またはキーワードを取得する

次の例は、正(負ではない)の整数値またはキーワードの入力をユーザに要求します。

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

    ;; The first parameter of InitializeUserInput (6)
    ;; restricts input to positive and non-negative
    ;; values. The second parameter is the list of
    ;; valid keywords.
    (vla-InitializeUserInput utilityObj 6 "Big Small Regular")

    ;; Set the prompt string variable
    (setq promptStr "\nEnter the size or [Big/Small/Regular] <Regular>: ")

    ;; At the GetInteger prompt, entering a keyword or pressing
    ;; ENTER without entering a value results in an error. To allow
    ;; your application to continue and check for the error
    ;; description, you must set the error handler to resume on error.

    ;; Get the value entered by the user
    (setq returnInteger (vl-catch-all-apply 'vla-GetInteger (list utilityObj promptStr)))

    ;; Check for an error. If the error number matches the
    ;; one shown below, then use GetInput to get the returned
    ;; string; otherwise, use the value of returnInteger.

    (if (vl-catch-all-error-p returnInteger)
        (progn
            (prompt (strcat "\n" (vl-catch-all-error-message returnInteger)))
            (setq returnString (vla-GetInput utilityObj))
            (if (= returnString "")  ;; ENTER returns empty string
                (setq returnString "Regular")  ;; Set to default
            )
        )
        (setq returnString (itoa returnInteger))  ;; Use the value entered
    )

    ;; Display the result
    (alert (strcat "Return value: " returnString))
)
(AutoCAD のみ)
Sub Ch3_UserInput()
  ' The first parameter of InitializeUserInput (6)
  ' restricts input to positive and non-negative
  ' values. The second parameter is the list of
  ' valid keywords.
  ThisDrawing.Utility.InitializeUserInput 6, "Big Small Regular"

  ' Set the prompt string variable
  Dim promptStr As String
  promptStr = vbCrLf & "Enter the size or (Big/Small/<Regular>):"

  ' At the GetInteger prompt, entering a keyword or pressing
  ' ENTER without entering a value results in an error. To allow
  ' your application to continue and check for the error
  ' description, you must set the error handler to resume on error.
  On Error Resume Next

  ' Get the value entered by the user
  Dim returnInteger As Integer
  returnInteger = ThisDrawing.Utility.GetInteger(promptStr)

  ' Check for an error. If the error number matches the
  ' one shown below, then use GetInput to get the returned
  ' string; otherwise, use the value of returnInteger.

  If Err.Number = -2145320928 Then
    Dim returnString As String
    Debug.Print Err.Description
    returnString = ThisDrawing.Utility.GetInput()
    If returnString = "" Then        'ENTER returns null string
      returnString = "Regular"     'Set to default
    End If
    Err.Clear
  Else                                 'Otherwise,
    returnString = returnInteger     'Use the value entered
  End If

  ' Display the result
  MsgBox "Return value: " & returnString
End Sub