Chapter 35: Exploring AutoLISP Further

In This Chapter

Creating variables and functions Working with AutoCAD commands and system variables Using lists to modify objects Setting conditions and creating loops Manipulating drawing objects Obtaining user input Finalizing a routine

AutoLISP offers many features that enable you to create sophisticated programs. These include variables, functions, and conditional statements. You can use these features to easily create drawing objects. You can retrieve information about drawing objects and then modify them. As a result, getting input from the user makes your programs more interactive.

AutoCAD Only

AutoCAD LT does not support AutoLISP. This entire chapter is for AutoCAD only.

Creating Variables

You can't do anything very useful in programming without using variables. A variable is a symbolic name that a program operates on. An important part of the usefulness of variables is that you can assign values to them. You use the setq function to name and assign a value to a variable.

The following example sets the value of 3 to a variable named radius.

(setq radius 3)


You can try this example in Visual LISP in the Console window. If you want to use this variable at the AutoCAD command line, precede it with an exclamation point (!). For example:

Command: !radius


The exclamation point before a variable evaluates the value that is stored in the variable and returns it to the command line. When you use a variable in the Console window that ...

Get AutoCAD® 2012 & AutoCAD LT® 2012 Bible now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.