Part Five - SpiralI added a simple error handler to catch any possible errors that the spiral program might generate. It is not really needed yet since we don't do anything that might need to be reset in an error handler. We will need it in Part Six. Also, with AutoCAD 2000 and later, errors no longer cause code to stream out to the console. So debugging at the command line is now more difficult when you want to see where an error occurred in the program. Even so, it is good practice to include the *error* function so that you have some control over how errors are handled. A single setq function can have multiple pairs of arguments. So to improve efficiency, I combined all sequential setq functions You should view the updated version of
Analyze CodeInclude an *error* Function... (defun *error* (%A) (cond ((= %A "Function cancelled") nil) (t (princ (strcat "\nerror: " %A "\007\n")))) (princ)) ... Any errors generated by AutoLISP are passed to a function named *error*. That function has a single argument, which is a string describing the error. The error function can do anything that you want; close any open files, terminate any active commands, reset any variables, or just alert the user. I included *error* in the local variable list so that it is active only for the spiral program. That way other lisp programs can define their own error handler.
Combine setq FunctionsExample:(setq #ABC 2.5) (setq #STRING "ABCDEFG") (setq #INT 3) (setq #ABC 2.5 #STRING "ABCDEFG" #INT 3) (setq #ABC 2.5 #STRING "ABCDEFG" #INT 3) Each of the three sequences above performs the same function. The first sequence may be the easiest to understand but is the least efficient. When combining a small number of setq functions, I'll often use a single line as demonstrated in the second sequence above. Since I was combining many setq functions in the spiral program, I followed the example from the third sequence shown above. Gracious Exit... (princ)) Normally a completed lisp function or program returns the last value that it encounters. In order to have a program complete without displaying any more information, a princ function is used with no string argument. I added the last princ call to the spiral program. The program now ends cleanly. In Part Six, I'll change the program so that it can work correctly regardless of the object snap settings. I'll also do a little more clean up.
|