The AutoCAD AutoLISP Extension offers several features that make it easier to write AutoLISP programs, such as IntelliSense and code snippets.
As you type in the editor window of an open AutoLISP source (LSP) file, the AutoCAD AutoLISP Extension displays a list of suggested functions and code snippets that match the characters typed. The more characters you type, the less items that will be displayed in the list. Select an item in the list to complete the function name or use the code snippet, you can also use the arrow keys to highlight the item to use and then press Tab to complete that item.
Small code blocks or samples, known as code snippets, are supported by the AutoCAD AutoLISP Extension. Code snippets can be used to quickly add the necessary syntax for commonly used functions or complex code blocks. For example, the AutoCAD AutoLISP Extension has a code snippet named ifp which is short for If… Progn and it contains an if statement with a nested progn statement. Typing ifp in the code editor and pressing Tab allows you to insert the code snippet.
Code snippets are part of the AutoComplete feature in VS Code and are prefixed by a square icon rather than a wrench used to indicate the name of an AutoLISP function.
The AutoCAD AutoLISP Extension codes ships with 60+ code snippets, here are a few of the code snippets that come with the AutoCAD AutoLISP Extension:
getlayer |
(setq layer (cdr (assoc 8 entname))) |
ifp |
(if (testexpr) (progn (thenexpr) ) ) |
line |
(command "_line" "pt1" "pt2" "") |
open |
(setq fp "fname.txt") (setq f (open fp "mode")) (close f) |
while |
(while testexpr [expr ...]) |
Code snippets for the AutoCAD AutoLISP Extension are stored in a file named snippets.json under one of these locations:
AutoLISP supports line and block comments. Comments can be manually added to any AutoLISP statement, but VS Code supports that ability to add and remove line and block comments to and from selected AutoLISP statements.
; Returns a CDATE value that includes milliseconds based on release ; Usage: (CDate) ; Replaces (rtos (getvar "CDATE") 2 8)
;| Returns a CDATE value that includes milliseconds based on release Usage: (CDate) Replaces (rtos (getvar "CDATE") 2 8) |;