Ask User for Input
Functions for Assigning Values to Variables
you will most often want to get information from the drawing area of the AutoCAD screen. AutoLISP offers a set of functions just for this purpose. These functions are characterized by their GET prefix. Below Table shows a list of these Get functions along with a brief description.
Functions that pause to allow input
FUNCTION |
DESCRIPTION |
Getpoint |
Allows key or mouse entry of point values. This always returns values as lists of coordinate values. |
Getcorner |
Allows selection of a point by using a window. this function requires a base point value defining the first corner of the window. The window appears, allowing you to select the opposite corner. |
Getorient |
Allows key or mouse entry of angles based on Units command setting for angles. Returns values in radians. |
Getangle |
Allows key or mouse entry of angles based on the standard AutoCAD compass orientation of angles. Returns values in radians. |
Getdist |
Allows key or mouse entry of distances. This always returns values as real numbers regardless of the unit format in use. |
To see how one of these functions works, try the following exercise.
(setq pt1 (getpoint))
This expression blanks the command line and waits until you enter a point. Just as with any standard AutoCAD command that expects point input, you can enter a relative or absolute point value through the keyboard or pick a point on the drawing area using the cursor. The coordinate of the point you pick will become the value assigned to the variable Pt1 in the form of a list.
To Check the value of pt1 by entering the following:
!pt1
The value i.e. (4.0 5.0 0.0) is returned and the command prompt appears once again
Notethat a Z coordinate value of 0.0 was added and that all the elements of the coordinate list are reals.
Adding Prompts
All these Get functions allow you to create a prompt by following the function with the prompt enclosed by quotation marks. The following demonstrates the use of prompts in conjunction with these functions.
Enter the following expression:
(setq pt1 (getpoint "Pick the first point :"))
The following prompt appears:
Pick the first point :
Move your cursor and pick a point on screen.
The Get functions allow you to specify a point from which the angle, distance, or point is to be measured.
Enter the following:
(setq pt2 (getcorner pt1 "Pick the opposite corner :"))
the following prompt appears:
Pick the opposite corner:
Pt1 is the point variable that holds the coordinate for the last point you picked. A window appears from the coordinate defined by Pt1.
Now Issue the line command and at the From point prompt, enter:
!pt1
A rubber-banding line appears from the point previously defined as pt1 just as if you had selected that point manually.
Now enter the following:
!pt2
A line is drawn from the point stored by pt1 to the point stored by pt2.