CADLisp Tools

Beginner tutorial

Create your first custom AutoCAD command

Use defun and the c: prefix to create a small interactive CAD command.

8 minUpdated Sep 17, 2026

An AutoLISP function whose name begins with c: becomes a command-line command.

Define a command

(defun c:ASKNAME (/ name)
  (setq name (getstring T "\nYour name: "))
  (prompt (strcat "\nHello, " name "."))
  (princ)
)

After loading the file, type ASKNAME. The local variable list (/ name) prevents name from leaking into the wider drawing session.

Read the expression from inside out

  • getstring asks for text.
  • setq stores the returned text in name.
  • strcat joins text values.
  • prompt writes a message to the command line.
  • princ gives the command a quiet exit.

Make the failure path clear

Real routines should check user input and handle cancellation. Keep the first version small, then add validation after the happy path works.

Use the function reference to inspect each building block.