AutoLISP has many "GETxxx" functions that pause for user input of the indicated type and returns the value of the same type entered. This is the method used to allow users to input values as needed in programs.
|
Allowable
input to the GETxxx user-input functions
|
||
|
Function
name
|
Type of
user input
|
User
presses ENTER, Returns
|
|
getint
|
An integer value on the command line
|
nil
|
|
getreal
|
A real or integer value on the command line
|
nil
|
|
getstring
|
A string on the command line
|
""
|
|
getpoint
|
A point value on the command line or selected
from the screen
|
nil
|
|
getcorner
|
A point value (the opposite corner of a box) on
the command line or 2 selected point from the screen
|
nil
|
|
getdist
|
A real or integer value (of distance) on the
command line or determined by selecting 2 points on the screen
|
nil
|
|
getangle
|
An angle value (in the current angle format) on
the command line or based on 2 selected points on the screen
|
nil
|
|
getorient
|
An angle value (in the current angle format) on
the command line or based on 2 selected points on the screen
|
nil
|
|
getkword
|
A predefined keyword or its abbreviation on the
command line
|
""
|
GETINT
Syntax - (getint [message])
Example -
(setq Inum (getint
"\nInput Integer ? "))
;type at command prompt
Input #1 -
Command: Input Integer ? 25
;integer input
returns: 25
Input #2 -
Command: Input Integer ? 25.0 ;real number
input
Requires an integer value
Input Integer
?
;allows user to re-input integer
Input #3 -
Command: Input Integer ? S
;non-numeric character entered
Requires an integer value
Input Integer
?
;allows user to re-input integer
Note - Values passed to getint can
range from -32,768 to +32,767. If the user enters any character other than a
number character, then getint displays the message "Requires
an integer value," and allows the user to try again.
GETREAL
Syntax - (getreal [message])
Example -
(setq Rnum (getreal
"\nInput Real Number ? "))
;type at command prompt
Input #1 -
Command: Input Real Number ? 25.0 ;real number
input
returns: 25.0
Input #2 -
Command: Input Real Number ? 25
;Integer input
returns: 25.0
Input #3 -
Command: Input Real Number ? S
;non-numeric character entered
Requires a numeric value
Input Real Number
?
;allows user to re-input number
Note - Values passed to getreal are
double-precision floating-point format. If the user enters any character other
than a number character, then getrealdisplays the message
"Requires a numeric value," and allows the user to try again. Real
numbers between -1 and 1 must be contain a leading zero. Real numbers can also
be expressed in scientific notation (example - 4.1e-6 equals 0.0000041).
GETSTRING
Syntax - (getstring [cr] [message])
[cr] = If supplied and is not nil, this will
allow the user to input spaces in their input string and must be terminated by
pressing ENTER. Otherwise, the input string is terminated by pressing the SPACE
or ENTER keys.
Example #1 -
(setq Stir
(getstring "\nInput String ? "))
;type at command prompt
Input #1 -
Command: Input String ? test
;String Input
returns: "test"
Input #2 -
Command: Input String ? 25.0
;Numeric Input
returns: "25.0"
Input #3 -
Command: Input String ? 25
;Numeric Input
returns: "25"
Input #4 -
Command: Input String ? C:\temp\ ;folder path input
returns: "C:\\temp\\"
Example #2 -
(setq Stag
(getstring T "\nInput String ? "))
;type at command prompt
Input #1 -
Command: Input String ? this is a test
;String Input
returns: "this is a test"
Note - getstring will
only return the first 132 characters in the input. If the input contains the
backslash character "\", getstring converts it to
two backslash characters "\\". This allows you to input folder paths.
GETPOINT
Syntax - (getpoint [pt] [message])
[pt] = If supplied and is not nil, this will
cause AutoCAD to show a rubberband from [pt] to current cursor
location
Example #1 -
(setq P1 (getpoint
"\nInput Point ? "))
;type at command prompt
Input #1 -
Command: Input Point ? pick point
;Point Input
returns: coordinates of picked point in list format
Input #2 -
Command: Input Point ? 25.0,25.0
;Numeric Input
returns: (25.0 25.0 0.0)
Input #3 -
Command: Input Point ? 25,25
;Numeric Input
returns: (25.0 25.0 0.0)
Input #4 -
Command: Input Point ? S
;string input
Invalid Point
Input Point
?
;allows user to re-input number
Example #2 -
(setq P0 (list 0.0
0.0))
(setq P1 (getpoint
P0 "\nInput Point ? "))
;type at command prompt
Input #1 -
Command: Input Point ? pick point
;Point Input showing rubberband from P0
returns: coordinates of picked point in list format
No comments:
Post a Comment