Aids in AutoLISP debugging

(trace [function...])

The trace function sets the trace flag for the specified functions. Each time a specified function is evaluated, a trace display appears showing the entry of the function (indented to the level of calling depth) and prints the result of the function.

If Visual LISP is active, trace output is sent to the Visual LISP Trace window. If Visual LISP is not active, trace output goes to the AutoCAD command window.

NoteOnce you start Visual LISP during an AutoCAD session, it remains active until you exit AutoCAD. Therefore, all trace output prints in the Visual LISP Trace window for the remainder of that AutoCAD session. Exiting or closing Visual LISP while AutoCAD is running only closes the IDE windows and places Visual LISP in a quiescent state; it does not result in a true shutdown. You must reopen Visual LISP to view the output in the Trace window.

Use untrace to turn off the trace flag.



A symbol that names a function. If no argument is supplied, trace has no effect.

Return Values

The last function name passed to trace. If no argument is supplied, trace returns nil.


Define a function named foo and set the trace flag for the function:

Command: (defun foo (x) (if (> x 0) (foo (1- x))))


Command: (trace foo)


Invoke foo and observe the results:

Command: (foo 3)

Entering (FOO 3)

 Entering (FOO 2)

  Entering (FOO 1)

   Entering (FOO 0)

   Result: nil

  Result: nil

 Result: nil

Result: nil

Clear the trace flag by invoking untrace:

Command: (untrace foo)


See Also