After you create an AutoLISP (LSP) file and add code statements to the file, you can connect Visual Studio Code to AutoCAD and step through your custom functions using many of the debug tools that Visual Studio Code offers.
Before debugging an LSP file, it is recommended to first open the LSP file you want to debug. The LSP file open in the current editor window will be loaded into AutoCAD when Visual Studio Code is initially connected to AutoCAD for debugging.
The following steps explain how to open the Create-LSP-Tutorial.lsp file in Visual Studio Code.
If the LSP Files folder is not open, click File menu > Open Folder/Open. Then browse to and select the LSP Files folder.
After the AutoLISP Extension has been properly configured and an LSP file is open in the current editor window, you are ready to debug the AutoLISP code statements stored in the LSP file with Visual Studio Code.
The following steps explain how to attach Visual Studio Code to AutoCAD for debugging.
Visual Studio Code should now be attached to AutoCAD with the LSP file in the current editor window loaded into the current drawing window.
You can tell if Visual Studio Code has successfully been attached to AutoCAD by the change in color to Visual Studio Code's status bar, it will change from Blue to Orange in color.

A message box appears with the text "Hello from AutoCAD!".

A line is drawing between the specified points and is placed on the current layer.
Breakpoints allow for the interruption of code statements as they are being executed. When execution is interrupted, you can:
The following steps explain how to add breakpoints to the Create-LSP-Tutorial.lsp file open in the current editor window.
A red circle appears indicating a breakpoint has been added.

The hello function is started and code execution is interrupted at the line with the breakpoint.


After specifying the first point, execution is interrupted by the inline breakpoint.

When execution is interrupted by a breakpoint, you can see the current value assigned to a variable or the value returned by a code statement.
In the previous section, you set two different breakpoints. The following steps utilize those breakpoints to interrupt code execution and view the value assigned to a variable.


Along with positioning the cursor over a variable to view its current assigned value in a tooltip, the values assigned to all local variables can be viewed in the Variables section on the Run view.


It is inevitable, while debugging your custom programs that you will encounter an error that needs to be fixed. Once fixed, you will want to test the changes made.
The following steps explain how to make a change to the drawline function and the reload the LSP file into AutoCAD while debugging with Visual Studio Code.
;; Draws a line between two points (defun c:drawline ( / pt1 pt2 sv_clayer) ;; Declared local variables ;; Store the current and create a new layer (setq sv_clayer (getvar "clayer")) (command "_.-layer" "_m" "Object" "_c" "5" "" "") ;; Prompt for two points (setq pt1 (getpoint "\nSpecify start point of line: ") pt2 (getpoint pt1 "\nSpecify end point of line: ") ) ;; Check to see if the user specified two points (if (and pt1 pt2) (command "_.line" pt1 pt2 "") (prompt "\nInvalid or missing point(s)") ) ;; Restore the previous layer (setvar "clayer" sv_clayer) ;; Exit quietly (princ) )

Visual Studio Code disconnects from AutoCAD and then re-attaches to the same AutoCAD process before loading the LSP file in the current drawing.
Notice this time the line is placed on the Objects layer which is assigned the color of Blue.
After you are done debugging an LSP file, you should disconnect Visual Studio Code from AutoCAD.
The following steps explain how to disconnect Visual Studio Code from AutoCAD.

The Debug toolbar closes and the status bar changes from Orange back to Blue in color.