In many AutoCAD commands, AutoCAD
remembers the last entry and puts that entry between angle brackets
Then all you have to do is press Enter, and that value is used. You should
use that technique whenever you're creating your own defaults in AutoLISP.
First make sure that you haven't declared as local the variable that will
hold the value. Then follow a three-step process :
Require input from the user and assign
that input to a second variable.
- Test to see if the input is nil, and
if it is nil, assign a global variable
to the real variable.
- Finally, assign the real variable to
the global variable.
- You're then ready for the next
Here's an example :
(defun c:prog1 (/ a)
(if (= gv nil)
(setq gv 1.0)
(princ "\nEnter Distance <")
(princ "> ")
(setq a (getdist))
(if (= a nil)
(setq a gv)
(setq gv a)
(princ "\nThe Distance is ")
gv is the global variable.
No matter how often you run this routine while in the same drawing, it
will maintain the last entry as the default. The first time through the
routine, gv is tested to see if it has a value. If it doesn't, the
routine assigns 1.0 as the default value.