Utility Functions to Improve Performance with autolisp
You may have noticed that our BOX1 program still doesn’t run as cleanly as most AutoCAD commands or other LISP routines that you may have previously used. After getting the core of a routine to work, you can add several simple functions to make it run more smoothly.
Explanation: Utility Functions
- Each of these special commands returns nil except (princ). The expression (princ) displays the null character ASCII 00.
Example “cmdecho”
Command: (setvar “cmdecho” 1)
Command: (command “line” “0,0” “1,5” “”)
line From point: 0,0
To point: 1,5
To point:
Command: nil
Command: (setvar “cmdecho” 0)
Command: (command “line” “0,0” “1,5” “”)
Command: nil
PRACTICE
Edit BOX1.LSP as indicated below to clean up the way it displays at the Command line and to ensure desired operation. Estimated time for completion: 5 minutes.
(defun c:BOX1 ()
(graphscr)
(prompt “This routine will draw a box”)
(setq CE-SAV (getvar “cmdecho”))
(setvar “cmdecho” 0)
(setq PT1 (getpoint “\nLower left corner: ”))
(setq PT2 (getpoint “\nLower right corner: ”))
(setq PT3 (getpoint “\nUpper right corner: ”))
(setq PT4 (getpoint “\nUpper left corner: ”))
(command “line” PT1 PT2 PT3 PT4 “close”)
(redraw)
(setvar “cmdecho” CE-SAV)
(princ)
)
- A complete solution to this exercise is on your class disk as BOX1-C.LSP.
- If you have time, edit the ACADDOC.LSP and add the following line:
(prompt “\nThe following programs have been loaded:
\nDegreesToRadians
\nRadiansToDegrees
(princ)