Assigning Values to Symbols with Autolisp

One of the most powerful features of AutoLISP is the ability to store a variable and then use it again later. In AutoLISP, these variables are called symbols, and they may be assigned a value using the (setq) function.

Explanation: the (setq) function

(setq symbol expression)

  • The (setq) function must have two arguments, the symbol name and an expression assigned to the symbol name.

Command: (setq A 12.0)

  • A single (setq) command can set any number of variables.

(setq symbol1 expression1
symbol2 expression2
symbol3 expression3
);end setq

  • A symbol evaluates to its value. You can see the current value of a symbol at any time by typing an exclamation point (!) prior to the symbol name.

Command: (setq B “This is text”)
“This is text”

Command: !B
“This is text”

  • If no value has been assigned to a symbol, then its value is nil.Command: !C
  • If several values have been assigned to a symbol, AutoLISP remembers only the last one assigned.


Try the following exercises using the (setq) function. Estimated time for completion: 5 minutes.

(setq A 5)
(setq B A)
(setq C (* A B))
(setq D (+ (* A B) C))
(setq D (+ D 15))

See also  why AutoLISP in AutoCAD?
Back to top button