AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN


Creating Defaults.

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 sequence.

Here's an example :

(defun c:prog1 (/ a)
	(if (= gv nil)
		(setq gv 1.0)
	);end if

	(princ "\nEnter Distance <")
	(princ gv)
	(princ "> ")
	(setq a (getdist))
	(if (= a nil)
		(setq a gv)
	);end if

	(setq gv a)
	(princ "\nThe Distance is ")
	(princ a)
	(princ)
);defun
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.
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website