关于控制用户输入 (ActiveX)
您可以使用该方法定义关键字或将输入类型限制为用户输入法。InitializeUserInput
use 和参数值类似于 AutoLISP 函数。 可以与以下方法一起使用:、、、和。 不能与该方法一起使用。当用户输入法未返回字符串值时,使用该方法检索字符串值(关键字或任意输入)。initgetInitializeUserInputGetAngleGetCornerGetDistanceGetIntegerGetKeywordGetOrientationGetPointGetRealInitializeUserInputGetStringGetInput
该方法接受两个参数。第一个参数是位编码整数值,用于确定用户输入法的输入选项。第二个参数是定义有效关键字的字符串。InitializeUserInput
在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))
)
- VBA(仅限 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
|