AutoLISP is a powerful productivity tool that allows you to automate workflows and extend the functionality of AutoCAD LT.
While AutoLISP isn't a new feature, it is now available in AutoCAD LT starting with the 2024 release.
The implementation of AutoLISP in AutoCAD LT lets you run most of the AutoLISP programs that have been developed over the past almost 40 years with some limitations. While you don't need to be an expert in AutoLISP to take advantage of many of the existing programs out there, learning AutoLISP programming is a skill that can unlock untapped productivity.
AutoLISP programs are commonly stored in a text file with the .lsp extension. Learning to load AutoLISP files is one of the first things you learn in the following exercises before learning some of the basics of AutoLISP programming. And no, you don't need prior programming experience to take advantage of AutoLISP. In many cases, a few new concepts and your current understanding of AutoCAD commands and system variables are all you really need.
When first getting started with AutoLISP, rather than writing your own programs, you will likely be loading an AutoLISP file that you found online, or your company created. AutoLISP files can be loaded:
The following methods can be used to load AutoLISP files at startup, upon the opening of a drawing, or manually.
Loading at Startup | Loading Manually |
---|---|
|
|
As you can see, AutoCAD LT is capable of loading AutoLISP files in a variety of ways. The methods you use depend on the configuration of your drafting environment. For now, we will look at loading an AutoLISP file with the Load/Unload Applications dialog box.
APPLOAD could also be entered at the Command prompt.
If you have a different language installed other than English, such as jp-jp, then select that folder instead of en-us.
The acadlt2024doc.lsp file is one of the specially named AutoLISP files that AutoCAD LT searches for and loads if found into each drawing that is opened or created. This AutoLISP file contains some commands and custom AutoLISP functions used by the product. Here, I'm just using it as an example file.
In the message box, "acadlt2024doc.lsp successfully loaded." is displayed in the lower-left corner of the dialog box and in the command line window.
This starts the DDGRIPS command defined by AutoLISP in the acadlt2024doc.lsp. The DDGRIPS command opens the Options dialog box and sets the Selection tab current.
In the previous exercise, you used the DDGRIPS command. I'm sure you are wondering how you would have known that is a command in the loaded AutoLISP file. Sometimes, programs might use some code that puts a message directly in the command line window so you know which commands are defined and can be used. However, that isn't always the case, and you might have to open an AutoLISP file to know which commands are defined. An AutoLISP file can be opened using Notepad.
The following image shows part of the acadlt2024doc.lsp file opened in Notepad. AutoLISP-defined commands that can be entered at the Command prompt are prefixed with c:. The text directly after c: is the name of the command.
While there is no specific place where you must store the AutoLISP files you download or create before using them, it is recommended to store them in a shared location. Like drawing templates and block libraries, you want to make sure all drafters in a team or in the company have access to the same AutoLISP files. You should consider:
Once you have identified a folder to store your AutoLISP files, you need to inform AutoCAD LT where the folder is located using the Support File Search Path and Trusted Locations settings on the Files tab of the Options dialog box. AutoCAD LT needs to know where your LSP files are located for the following reasons:
The following steps show how to add the folder C:\AutoLISP Files to the Support File Search Path and Trusted Locations settings. You will use this location later to create an LSP file with a few short AutoLISP programs.
The listed folders are where AutoCAD LT looks for your AutoLISP files among other types of custom files used to store hatch patterns, linetypes, command aliases, and define new user interface elements.
The folder is added to the bottom of the list.
The folder is added to the bottom of the list.
In addition to marking the folders with your AutoLISP files as read-only and identifying those folders as trusted, AutoCAD LT also offers some additional settings that help to secure AutoCAD LT from malicious code and malware. You can access the Security settings of AutoCAD LT by doing the following:
Being able to load and manage AutoLISP files that you find online, or your company already has, is just the beginning of becoming more productive with AutoLISP in AutoCAD LT. After you start using the AutoLISP programs from the AutoLISP files you already have in your everyday workflows, there may come the day when you want to make a change to them or even write your own basic AutoLISP programs.
You might be thinking to yourself, AutoLISP is a programming language and that you aren't a programmer. While true, AutoLISP is a programming language, you don't need to be a programmer to learn and write AutoLISP programs. The simplest AutoLISP program is a single statement that allows you to execute a command or change the value of a system variable.
An AutoLISP statement begins with an open parenthesis and ends with a closing parenthesis. The following is an example of an AutoLISP statement that turns Ortho Mode on with the ORTHOMODE system variable.
(setvar "orthomode" 1)
Like command and system variable names, AutoLISP statements can be entered at the Command prompt in AutoCAD LT. Let's give it a try:
The status bar button is gray in color when disabled.
The Ortho Mode button on the status bar should now be enabled and blue in color.
Congratulations on writing your first AutoLISP statement! You are now a programmer!
The previous AutoLISP statement utilizes the setvar function to set the value of a system variable. There is also a function that returns the current value of a system variable named getvar. The setvar and getvar functions are just two out of hundreds of functions that can be used to automate workflows using AutoLISP. While there are hundreds of functions that make up the AutoLISP programming language, you only need to understand five key functions to get started. Two of which you have already learned about. The five functions are:
Now that you know the five key functions and have used the setvar function to set a system variable, let's look at using the command function. Before continuing, you should know that command names can be prefixed with . (period) and _ (underscore) characters while command option names can be prefixed with an _ (underscore) character. These characters are used to ensure the provided command executes as expected.
Here is an explanation of what these characters mean:
In the following steps, you draw a circle and zoom to the extents of the drawing using the command function.
A circle is drawn on the current layer with a radius of 5 units at 5,5.
The drawing is zoomed to the extents of the circle if that is the only object in the drawing, else it zooms to the extents of all objects in the drawing.
Now that you have seen some AutoLISP statements, let's take a closer look at the various parts and syntax of the example AutoLISP statements:
While entering AutoLISP statements directly at the Command prompt is a great way to start learning AutoLISP since you get feedback in real-time, it isn't very efficient to repeatedly retype statements at the Command prompt. One approach to allow you to reuse AutoLISP statements is to group them as a custom command with the defun function.
Let's give the defun function a try and define a custom command named ZP that zooms to the previous view of the drawing:
C:ZP is output to the command.
The previous view is restored.
The previous view is now restored.
Even though you can define custom commands with the defun function to make the reuse of AutoLISP statements easier, the commands you define are only available in the drawings of which they are defined, and while the drawing remains open. In the next section, you'll learn how to create an AutoLISP file to store your custom AutoLISP commands along with other AutoLISP statements that you might want to execute upon the loading of the AutoLISP file.
You can learn more about the five key functions along with the hundreds of other available functions in the AutoLISP Reference Guide.
Now that you know how to enter AutoLISP expressions at the Command prompt, let's look at how we can create an AutoLISP file and store your AutoLISP expressions and custom commands to make them available when you need them. AutoLISP files are plain ASCII text files that can be created with a simple text editor, such as Notepad, and have the file extension of .lsp. It is not recommended to use a word processor application like Write or Word as it can introduce specialized characters and formatting that will cause problems when it comes time to load the LSP file.
In the next exercises, you learn how to create an LSP file, add some AutoLISP statements to the LSP file, load the LSP file, and then try the commands defined in the LSP file. In addition to the five key functions mentioned earlier, you are also introduced to:
Now let's create our own file and load it into AutoCAD LT:
; Zoom commands (defun c:ze () (command "._zoom" "_e")) (defun c:zp () (command "._zoom" "_p")) ; Creates the layer A-ANNO-REV, draws a rectangle and ; converts the rectangle to a revision cloud with arc lengths ; based on half the current value of the LTSCALE system variable (defun c:rv () (setq old-layer (getvar "clayer")) (command "._-layer" "_m" "A-ANNO-REVCLD" "_c" "1" "" "") (command "._rectang" PAUSE PAUSE) (command "._revcloud" "_a" (/ (getvar "ltscale") 2) "" "_o" "_l" "_n") (setvar "clayer" old-layer) ) ; Display a general message in the command line upon load (prompt "\nLoaded MyFirst.lsp") (princ)
If your programs need to utilize Unicode characters, select UTF-8.
Now that you have created the file, instead of using the Load/Unload Application dialog box that is displayed with the APPLOAD command, you will load the LSP file using File Explorer.
Once loaded, you should see the message "Loaded MyFirst.lsp" in the command line window history which was displayed by the prompt function.
Notice the revision cloud is red and placed on the layer A-ANNO-REVCLD. This can be seen from the Layer drop-down list on the Layers panel of the ribbon or the Properties/Quick Properties palettes.
The drawing is zoomed to its extents.
The previous view of the drawing is restored.
The Load/Unload Application dialog box can be used to not only manually load AutoLISP files as they're needed, but it can also automatically load AutoLISP files upon the opening or creating of a new drawing file. The Startup Suite area of the Load/Unload Application dialog box is used to specify which AutoLISP files to automatically load.
Here are the steps used to add an AutoLISP file to the Startup Suite:
APPLOAD could also be entered at the Command prompt.
If you created the myfirst.lsp file in the previous section, you could select that file.
The AutoLISP file you added to the Startup Suite is automatically loaded into the current drawing.
When AutoCAD LT starts up or a drawing is created/opened, AutoCAD LT looks for four AutoLISP files with specific names. If the files are found, they are automatically loaded. These files help to make sure the AutoCAD LT environment is configured as expected and that your AutoLISP defined commands are available upon the creation or opening of a drawing.
AutoCAD LT looks for and automatically loads these four files when found in its support paths:
acadlt.lsp and acadltdoc.lsp must be created by you; they are not part of the standard AutoCAD LT installation. acadlt2024.lsp and acadltdoc2024.lsp are included with the program and shouldn't be modified.
You can utilize the acadlt.lsp and acadltdoc.lsp files like any other LSP files with the addition of these files automatically being loaded under the previously mentioned contexts. These two files can be used to load other AutoLISP files using the AutoLISP load function, execute AutoLISP statements as these files are being loaded, and define AutoLISP command definitions so they are ready for use once a drawing has been created or opened. The AutoLISP load function accepts two parameters; the AutoLISP file to load which is required and a second optional parameter that is a message to be displayed if the AutoLISP file being loaded is not found in one of the support file search paths of AutoCAD LT. See the Manage and Secure AutoLISP Files section on setting up support file search paths.
The following steps explain how to create the acadltdoc.lsp file in the C:\AutoLISP Files folder, add a few AutoLISP statements to it, load it into AutoCAD LT, and then verify the file was loaded.
; AutoLISP to be executed in each drawing created or opened ; Set Object Snap and Ortho modes (setvar "osmode" 4133) (setvar "orthomode" 1) ; Load the LSP file created earlier under the ; "Store AutoLISP Statements in AutoLISP (LSP) Files" section (load "myfirst.lsp" "\nMyFirst.lsp file couldn't be found") ; Display a general message in the command line upon load (prompt "\nLoading my custom programs") (princ)
In the command line window, you should see the message "Loading my custom programs" which is from one of the last two lines you entered earlier in step 2.
The status bar buttons should once again be enabled.
A plug-in bundle is a folder structure with a manifest file named PackageContents.xml file that informs AutoCAD LT of the files and settings that make up the plug-in. While plug-in bundles are not required for loading AutoLISP programs into AutoCAD LT as you have already learned throughout this article, they can make the managing of AutoLISP files easier and are a safer way to deploy custom programs than with the use of the acadlt.lsp or acadltdoc.lsp files. Plug-in bundles can also help configure AutoCAD LT without the need of the Options dialog box in most cases.
For information on plug-in bundles, see the Example: Basic .bundle Folder Structure for a Plug-in.
Automating your workflows can help improve your productivity and reduce repetitive tasks. While AutoLISP programming does have a learning curve, if you stick to learning the five key functions, you can make some small programs that help you realize just how valuable AutoLISP can be in your everyday workflows.
Here are some frequently used commands and system variables related to AutoLISP.
Command | Description |
---|---|
APPAUTOLOADER | Lists or reloads all plug-ins in the application plug-in folder. |
APPLOAD | Loads and unloads applications and defines which applications to load at startup. |
OPTIONS | Customizes the program settings. |
SECURITYOPTIONS | Controls the security restrictions for running executable files in the product. |
UNDEFINE | Allows an application-defined command to override an internal command. |
System Variable | Description | Default Value | Saved in |
---|---|---|---|
ACADLSPASDOC | Controls whether the acad.lsp file, or acadlt.lsp file for AutoCAD LT, file is loaded into every drawing or just the first drawing opened in a session. | 0 | Registry |
APPAUTOLOAD | Controls when plug-in applications are loaded. | 14 | Registry |
CLAYER | Sets the current layer. | 0 | Drawing |
CLIPROMPTUPDATE | Controls whether the command line displays the messages and prompts generated while an AutoLISP or script file is being executed. | 1 | Registry |
CMDDIA | Controls the display of the In-Place Text Editor for the DIMEDIT and QLEADER commands, and the display of certain dialog boxes in AutoCAD-based products. | 1 | Registry |
CMDECHO | Controls whether prompts and input are echoed during the AutoLISP command function. | 1 | Not-saved |
FILEDIA | Suppresses display of file navigation dialog boxes. | 1 | Registry |
LEGACYCODESEARCH | Controls whether searching for executable files includes the folder from which the program is started. | 0, may be locked by a CAD administrator | Registry |
NOMUTT | Suppresses the message display (muttering) when it wouldn't normally be suppressed. | 0 | Not-saved |
ORTHOMODE | Constrains cursor movement to the perpendicular. | 0 | Drawing |
OSMODE | Sets running object snaps. | 4133 | Registry |
SECURELOAD | Controls whether executable files are restricted to being loaded from trusted folders only. | 1, may be locked by the CAD administrator | Registry |
TEXTEVAL | Controls how text strings entered with TEXT (using AutoLISP) or with -TEXT are evaluated. | 0 | Not-saved |
TRUSTEDPATHS | Specifies which folders have permission to load and execute files that contain code. | Varies, may be locked by a CAD administrator | Registry |