Troubleshooting AutoLISP Files

Whenever you work with AutoLISP you will come across errors. Sometimes this is nothing more than a misspelling of a function or, very often, the wrong number of parentheses. Below are some common errors and some possible solutions.

Explanation: the (type) function

The “error: bad argument” message means that you have used the wrong data type. Quite often the arguments will be stored in a symbol so you will not be able to see what type of data it is. You can use the AutoLISP function (type) to find out.

(type element)

Examples

Command: (setq A 1.0)
(type A)
REAL

Command: (type “This is”)
STR

Command: (type 1783)
INT

Using Visual LISP’s Check Function

Before you load a file it is a good idea to check it. Check Edit Window and Check Selection will tell you if you have too many or two few arguments to a known function.

  • Any error messages will be shown in a Build Output window.

  • If you double-click on the error in the Build Output window it will highlight the appropriate lines in the AutoLISP code.
  • Some problems will not come clear until you actually load the command. For example, Check cannot tell if you need an integer and you passed on a string. Use the (type) command or other debugging tools if you have this problem.
See also  why AutoLISP in AutoCAD?

PRACTICE

In this practice we will create some problems for the BOX1.LSP file and then use tools in Visual LISP to fix the problems. Estimated time for completion: 5 minutes.

1. Continue using BOX1.LSP.

2. Erase the closing quote mark (“ ) after one of the prompts. Notice how the color of all the following lines change. Where does the new string end?

3. Double-click in front of the opening parenthesis of that same line. What happens?

4. Add a close quote and two close parentheses at the end of the file. Try double-clicking at the same place again.

5. Check the whole file. What happens?

6. Double-click on the error message in the Build Output window.

7. What is highlighted?

8. Fix the problem(s), check the routine again, and run it to make sure it works.

Back to top button