What it does
defun creates a reusable function. A function named c:NAME can be invoked by typing NAME at the CAD command line.
Simple example
(defun double (number)
(* number 2)
)
Calling (double 4) returns 8.
Practical CAD example
(defun c:SAYLAYER (/ layer)
(setq layer (getvar "CLAYER"))
(prompt (strcat "\nCurrent layer: " layer))
(princ)
)
Common mistakes
- Forgetting parentheses around the argument/local-variable list.
- Forgetting to localize temporary variables after
/. - Including spaces or unsuitable punctuation in a command name.