;| ADD.lsp Adds a series of numbers entered in any valid AutoCAD UNITS format(s), displays the result in current units as well as in decimal units, and returns the result as a real number in the global symbol AddSum for use at the command line or in other functions. Numbers and distances can be entered either from the keyboard or by indicating pairs of points on the screen. Negative numbers and 0 are accepted from the keyboard. Distances indicated on the screen are always positive. LISP symbols, LISP functions, and calls to the 'cal function are not accepted. Subsequent uses of ADD.lsp can start with the prior result by entering [Enter] at the first prompt: Command: add Enter a number or distance, or [Enter] to start with 4'-6": = 0" + (Enter) = 4'-6" + 3'2.5 = 7'-8 1/2" + (Enter) AddSum = 7'-8 1/2" [92.50000000] by Bill Gilliss bill at realerthanreal dot com Comments and suggestions always welcome. No warranty, either expressed or implied, is made as to the fitness of this information for any particular purpose. All materials are to be considered 'as-is', and use thereof should be considered as at your own risk. ver 1.0 Nov 15 2008 ver 2.0 Jan 25 2010 - initial public release Keywords: AutoCAD AutoLISP add addition =========================================================================== |; (defun c:add ( / value *lunits *error*) (defun myerror (msg) (setvar 'lunits *lunits) (setq *error* myerror) ) (setq *error* myerror) (setq *lunits (getvar 'lunits)) (setvar 'lunits 4) ;to accept any input format, incl scientific and arch. (if (numberp addsum) (progn (princ (strcat "\nEnter a number or distance, or [Enter] to start with " (rtos AddSum) ": ")) (princ (strcat "\n= " (rtos 0 *lunits) " + ")) (initget 32) ; null, 0, and negatives permitted (setq value (getdist)) (if (/= value nil)(setq addSum value)) ) (progn (princ "\nEnter a number or specify a distance: ") (setq addSum 0) ) ) (setq value 0) (while (/= value nil) (princ (strcat "\n= " (rtos AddSum *lunits) " + ")) (initget 32) (setq value (getdist)) (if value (progn (setq AddSum (+ AddSum value)) ) ) );while (setvar 'lunits *lunits) (princ (strcat "\nAddSum = " (rtos AddSum *lunits) " \[" (rtos AddSum 2 8) "]")) (princ) );defun (princ "ADD loaded. Result will be stored as a real in variable AddSum.") (princ)