AU Class
AU Class
class - AU

Leveling Up with AutoLISP in AutoCAD LT 2024

共享此课程
在视频、演示文稿幻灯片和讲义中搜索关键字:

说明

This session will provide a general understanding of how to use and work with AutoLISP in AutoCAD LT software. Users will start by learning what AutoLISP is and which file formats are associated with it. Following an introduction of AutoLISP, users will learn to load and use AutoLISP programs, and discover some best practices for managing these files. After learning how to load, use, and manage AutoLISP program files, users will learn the basics of writing and modifying AutoLISP programs. These basics will focus on understanding the syntax of AutoLISP statements and five core functions: setvar, getvar, command, setq, and defun. As part of learning the basics, users will enter AutoLISP statements directly at the Command prompt to get immediate feedback before learning to store AutoLISP statements in an LSP file.

主要学习内容

  • Learn how to load and use AutoLISP programs.
  • Learn how to manage AutoLISP program files.
  • Learn how to understand and write AutoLISP statements.
  • Learn how to save AutoLISP statements to LSP files.

讲师

  • Lee Ambrosius
    Lee Ambrosius is a Senior Principal Content Experience Designer at Autodesk, Inc., for the AutoCAD® and AutoCAD LT products on Windows and Mac. He works primarily on the customization, developer, and CAD administration documentation along with the user documentation. Lee has presented at over 15 different Autodesk University events on a range of topics, from general AutoCAD customization to programming with the ObjectARX technology. He has authored several AutoCAD-related books, with his most recent projects being Discovering AutoCAD 2024, and AutoCAD Platform Customization: User Interface, AutoLISP, VBA, and Beyond. When Lee isn't writing, you can find him roaming various AutoCAD community forums, posting articles on his or the AutoCAD blog, or tweeting information regarding the AutoCAD product.
Video Player is loading.
Current Time 0:00
Duration 0:00
Loaded: 0%
Stream Type LIVE
Remaining Time 0:00
 
1x
  • Chapters
  • descriptions off, selected
  • subtitles off, selected
      Transcript

      LEE AMBROSIUS: Hello, and welcome to "Leveling Up with AutoLISP in AutoCAD LT 2024." This is our Safe Harbor Statement. Please review it when you get a chance.

      This session is for those that want to automate workflows and repetitive tasks in AutoCAD LT using AutoLISP. You should already be familiar with AutoCAD LT and know how to use commands, and at least know what system variables are. You don't need any prior programming experience for this session, as it starts with the very basics.

      Before getting started, a little about myself. My name is Lee Ambrosius, and I'm a senior principal content experience designer at Autodesk. In this role, I'm the primary technical writer for the customization, developer, and CAD administration documentation. I also perform some data analytic work on AutoCAD and AutoCAD LT. I have been using AutoCAD since 1994 and have around 25 years of experience customizing and developing applications on AutoCAD.

      Outside of Autodesk, I have worked on several AutoCAD books in the past seven years. One of these books is AutoCAD Customization Platform, which does cover AutoLISP and other ways of automating tasks in AutoCAD. But some of that content will also apply to AutoCAD LT now.

      Beyond AutoCAD, I like to run and enjoy going to Disney. So I often combine both of those into a vacation at Disney during Run Disney weekends. Here I am about six years ago after finishing Dopey, which is four races in four days-- 5K, 10K, half, and full marathon, for a total of 48.6 miles. I do have a dream of running an ultra marathon, or even a 50-mile race someday.

      Things to know before getting started-- before getting started, you should install AutoCAD LT 2024. AutoCAD LT 2023 and earlier don't support AutoLISP programming. You will also need Notepad. Luckily for us, it is already installed as part of Windows. The handouts and data set for this session will also be beneficial. In the handouts, you will find 15 exercises to help you understand the basics of and more advanced topics about AutoLISP programming.

      What you will learn-- this session is organized into learning two workflows related to using AutoLISP, using and managing AutoLISP files, and writing your own AutoLISP statements and files. After this session, you will know how to load and use AutoLISP program files, manage AutoLISP program files, understand the AutoLISP syntax of and how to write and edit AutoLISP statements. And save AutoLISP statements to LSP files. As we go through this session, be aware that I may use the words expression and statement interchangeably.

      We start off by looking at the use and manage AutoLISP files workflow. In this workflow, you start by understanding how to load AutoLISP files and then identifying the commands in an LSP file that can be used at the command prompt.

      Introduction to AutoLISP-- AutoLISP is a programming language based on the LISP programming language developed in the 1960s for AI. LISP stands for LISt Processing. AutoLISP was first introduced in AutoCAD 2.18 over 35 years ago, and just recently with AutoCAD LT 2024. Using AutoLISP, you can automate drawing workflows, read/write information stored outside of a drawing, and enforce CAD standards. As the session progresses, you will learn that AutoLISP statements can be entered directly at the command prompt in AutoCAD LT and loaded from an AutoLISP file.

      So why AutoLISP? Well, AutoLISP is much more functional for automating workflows than scripts. Scripts are nice, but they don't make logical decisions like an actual programming language. AutoLISP has been around for 35-plus years, which means that there are tens of thousands, if not hundreds of thousands of programs out there that can be used in AutoCAD LT with no to minimal changes. It is also included with AutoCAD LT 2024. Nothing else needs to be installed to take advantage of it. And finally, it builds on your existing knowledge of commands and system variables that you already know and use today.

      Loading an AutoLISP file-- AutoLISP programs are commonly stored in files with the LSP, FAS, VLX, and MNL extensions. LSP files are the most common type and is what I will be working within this session. You can find AutoLISP files for download on the internet, or even possibly within your own company. LSP files can also be created to store and load your custom programs, which you will learn how to create during this session. AutoLISP files must be loaded into each drawing in which you want to use them.

      After you have an AutoLISP file, to use the programs defined in that file, it must be loaded into AutoCAD LT. AutoCAD LT supports many different ways to load AutoLISP files on a per drawing basis or automatically into each drawing file opened. AutoLISP files can be loaded by dragging and dropping them from File Explorer into a drawing window. AutoLISP files can also be manually loaded using the Load/Unload Applications dialog box, which can be displayed using the Load Application button from the Applications panel on the Manage tab of the ribbon or using the APPLOAD command directly.

      Additionally, the Startup Suite in the Load/Unload Applications dialog box can also be used to load AutoLISP files into not only the current drawing, but all future drawing files opened in AutoCAD LT. When I say drawing files that are opened, I'm referring to new drawings you create or existing drawing files that you open in AutoCAD LT.

      In this demo, you see how to load an AutoLISP file named samples.lsp using the drag and drop method, the Load/Unload Applications dialog box, and the Startup Suite of the Load/Unload Applications dialog box. Here the LSP file is being dragged and dropped from File Explorer into the open drawing.

      This next example shows loading the LSP file with the Load/Unload Applications dialog box. And finally, the last example shows how to add the LSP file to the startup suite.

      If you only need to use an AutoLISP file occasionally, you can drag and drop the file into the open drawing, or load it using the Load/Unload Applications dialog box. AutoLISP files you want to use frequently can be added to the Startup Suite, as these files are automatically loaded into each drawing opened. The AutoLISP load function, specially named LSP files, acadlt.lsp and acadltdoc.lsp, and plug-in bundles can also be used to load AutoLISP files into each open drawing. These other methods are covered in the handout for this session.

      Identifying commands in LSP files-- LSP files are plain text files, which can be viewed in an application like Notepad. FAS and VLX files, however, can't be viewed with Notepad because they are compiled in protected files. MNL files can, however, be opened and viewed in Notepad, just like LSP files.

      When viewing an LSP file to see which commands are defined and that can be started from the command prompt in AutoCAD LT, you want to look for two things-- the use of the defun function and the use of the C colon prefix in front of the function name. The defun function is used to define custom commands with the AutoLISP programming language. You will learn more about the defun function and how to create your own custom commands with AutoLISP later in this session.

      Commands defined in a loaded AutoLISP file behave similar to commands that are natively defined in AutoCAD LT. In this demo, you see how to identify commands in an LSP file that can be started at the AutoCAD command prompt in AutoCAD LT. Here we continue to use the samples.lsp file that was loaded in the previous demo.

      To identify commands in a LSP file, it can be opened in Notepad. Once opened, we can then search for the c colon prefix of the function name being defined with the defun function. These function names let us know they can be entered at the command prompt in AutoCAD LT similar to native commands.

      The dl_autolisp command draws a single line segment from 0 comma 0 to 15 comma 15 with the line command. The mytext_autolisp command creates mtext on the layer ts-text2 with the style name Sans Serif Bold.

      Now that you know how to load AutoLISP files and identify the commands defined in an AutoLISP file, we will look at how AutoLISP files are managed in AutoCAD LT.

      Managing and trusting AutoLISP files-- on the Files tab of the Options dialog box, there are two settings related to managing and trusting AutoLISP files, Support File Search Path and Trusted Locations. Paths under Support File Search Path are used by AutoCAD to locate AutoLISP and other custom files, such as blocks, line types, and fonts.

      Trusted Locations are used to help secure AutoCAD LT. These locations are used by AutoCAD LT to know where it's safe to load AutoLISP files from to reduce exposure to malware. It is recommended that these locations to be read-only. Any trusted location being added must have already been added to the Support File Search Path setting.

      When AutoLISP files are loaded outside of a trusted location, a warning message is displayed to inform you of this occurrence. One of these warnings was previously displayed while loading AutoLISP files earlier. In this demo, you see how to add the folder, which contains the data set for this session to the Support File Search Path and Trusted Location settings.

      Folder settings are managed in the Options dialog box. On the Files tab, you can find the Support File Search Path setting, which is selected by default. Here the data set folder for this session is being added as a support file search path, and then as a trusted location.

      As a reminder, it is recommended Trusted Locations should be read-only. Now, with the path added, I will load the samples.lsp file again. Notice this time no warning is displayed because the folder in which the file is located is now trusted.

      In addition to trusted locations, AutoCAD LT offers some additional security-related settings, which can be found in the Security Settings dialog box. This dialog box can be displayed from the System tab of the Options dialog box, or with the Security Options command. These settings allow you to restrict the loading of AutoLISP files, where executable files are searched from, and how the acadlt.lsp file is loaded, per drawing or once per session.

      This completes the first workflow of working with AutoLISP, learning how to use and manage AutoLISP files. From this point forward, I'm going to be talking about how to use the AutoLISP programming language to create custom programs, starting with the basics of the AutoLISP programming language and its syntax.

      Learning the basics of AutoLISP-- AutoLISP programs are made up of many statements. AutoLISP statements consist of a function and any required values. An AutoLISP function can be used to execute a command, create, modify drawing objects, store, convert, and manipulate values, request input from the user, perform logical tests for a program to make decisions, and much more.

      While there are hundreds of functions in core AutoLISP, there are only five you need to learn about when first getting started-- command, which executes an AutoCAD LT command; setq assigns a value to a user-defined variable; setvar assigns a value to a system variable; getvar retrieves the current value of a system variable; and defun, which creates a user-defined function or command.

      Syntax of AutoLISP statements-- AutoLISP statements begin with either an open parenthesis or exclamation point. An open parenthesis starts the use of a function. An exclamation point returns the value of a user-defined variable and can only be used at the AutoCAD LT command prompt. A closing parenthesis must follow each open parenthesis to end an AutoLISP statement. AutoLISP statements are not case sensitive, except when using string values. In a string, uppercase letters are different from lowercase letters, while in a function or variable name, upper and lowercase letters have the same meaning.

      Additionally, all AutoLISP statements return a value. This means they do something based on the values you provide, and they return something back to you.

      Just about all AutoLISP statements have the same syntax. They start with an open parenthesis, which is followed by the function name being used. After the function name is any required arguments separated by a space. An argument is a placeholder for the values being passed to the function. After the last argument is a closing parenthesis that ends these statement started by the open parenthesis. Not all functions have arguments and expect values.

      Here are some examples of AutoLISP statements. The first assigns a value of 5.125 to a user-defined variable named dRadius. The second example gets the current value of the dRadius variable using an exclamation point. The third example draws a line from 0 comma 0 to 5 comma 5. Notice the use of the line command here. You already know how to use the line command, so this simply is just a natural extension of what you already know.

      The next example sets the filletrad system variable to a value of 0.25. The fifth example defines a custom function named ZX, which behaves similar to a standard AutoCAD LT command. This function executes the ._zoom command and zooms to the extents of the drawing.

      The second to last example returns the sum of four numbers, which in this case is 6, while the last example is used to force the display of a dialog box if the following command can display a dialog box. Notice the last example. There are no values passed to it because it doesn't expect any.

      As I mentioned previously, AutoLISP functions return a value. This allows you to nest AutoLISP statements and reduce the complexity of your custom programs. Nested statements are evaluated inner to outermost, similar to how parentheses are evaluated in the order of operations for mathematics.

      Here's an example of a nested function that adds 15 to the result of 2 times 12. 2 is multiplied by 12 first, which is 24. And that value is then added to 15 for a final value of 39.

      Here are some examples of nested AutoLISP statements. The first example defines a custom function named ZX, which behaves similar to a standard AutoCAD command. As I previously mentioned, this one performs a ._zoom extents of the drawing. The second draws a circle at 0 comma 5 comma 0 at a radius of 2. The nested statement here is the creation of the coordinate value 0 comma 5 comma 0, which is a list. The final example takes the nested statements from the previous slide and assigns them to a user-defined variable named dAngle. The value of 39 is assigned to dAngle.

      In this demo, you see how AutoLISP statements can be entered directly at the command prompt in AutoCAD LT and get immediate feedback in the form of the return value or a request for user input. At the command prompt, entering an open parenthesis instructs AutoCAD LT you want to work with AutoLISP.

      After pressing Enter, notice the command prompt message changes, letting you know you are working with AutoLISP. Here I'm going to use the setq function to assign a value to the user-defined variable named dRadius. Typing in a closing parenthesis and pressing Enter causes the AutoLISP statement to be evaluated and returns the value that was assigned, which was 5.125. Next, an exclamation point can be used in front of the user-defined variable, dRadius, to get its current value.

      In this final statement, I'm going to use the command function with the erase command to erase all the objects within the drawing. Notice the use of the double quotation marks to indicate a string and not a numeric or coordinate value. Here string values are used for the command and option names passed to the command function. The empty pair of double quotation marks at the end represents the pressing of the Enter key.

      Work with commands-- in the previous demo and earlier, you saw examples of the command function. Remember, the command function is used to execute AutoCAD LT commands, but not those that you create or define with AutoLISP yourself. The command function doesn't require you to provide any values. When no values are passed, it acts like a cancel, or the pressing of the Escape key. When a value is passed to the command function, it is typically the command_name you want to execute. Optionally, you can provide values after the command_name that represent input and option names for that command and use.

      Command and option names must be in double quotation marks, as they need to be represented as strings. Command names can be prefixed with a period and/or an underscore character. A period ensures the native command behavior is used. AutoCAD LT commands can be changed with AutoLISP. An underscore character indicates the use of the global name for a command or option.

      As you've already seen, an empty pair of double quotation marks represents the pressing of the Enter key when using the command function. When you want the user to provide a value to a command while using the command function, you can use the PAUSE variable instead of a static value. AutoCAD LT will request the user to provide a value based on the active prompt and continue execution after a valid value has been provided.

      Here are some examples of statements that use the command function. The first draws a line from 0 comma 0 to 5 comma 5. Notice the use of the empty pair of double quotation marks at the end of the line command. This ends the line command after a single segment has been drawn.

      The second example zooms to the extents of the drawing. The third example creates an mtext object at the height of 0.75. Notice the use of the pause variable to allow the user to specify the first and opposite corners of the text boundary box. The final example draws a circle at 5 comma 5, and then chooses the diameter option. The user is then allowed to provide a value for the diameter because of the use of the pause variable.

      Here's an example of a command sequence you might perform at the command prompt to create a layer named TS-TEXT2, a text style named SANSERIFBOLD, and then create an mtext object with a height of 0.75.

      Here's the same sequence as AutoLISP statements. Command names and options and values are indicated by the orange color. String values are surrounded by double quotation marks. Empty quotation mark pairs represent a press of the Enter key. And the PAUSE variable is used to indicate a request for user input. The first statement creates our layer. The second statement creates our text style. And the third command statement starts our mtext command.

      The behavior of some commands can be modified by prefixing a command with a hyphen, such as -insert, -layer, or -purge. The use of the hyphen forces the use of the command line version of the command. This can be useful to use-- some commands that normally display dialog boxes without the use of the dialog box itself. Using the initdia and the initcommandversion functions before the command function and changing the values of system variables, such as CMDDIA and file FILEDIA. These are not discussed in detail during the session, but things to be aware of.

      In this demo, you see how to create a layer, draw a circle and line, and zoom to the extents of the drawing using the respective commands with the command function. I start by passing the hyphen layer command name to the command function. To create a layer, you use the make option, followed by the layer name.

      Here, the color option is being used to assign the new layer the color of red. To accept the color assignment for the new layer and end the command, two empty double quotation mark pairs are provided. You can see the new layer in the layer control on the ribbon.

      Next, I'm going to use the circle command to draw a circle with a radius of 1 at 2 comma 2. To see the circle, I'll zoom to the extents of the drawing.

      For the last statement I enter, I'm going to use the line command to draw a single line segment from 0 comma 0 to a user-specified point. The pause variable is used to allow me to provide that point. Here the empty double quotation mark pair ends the line command after the point is specified.

      Understand data types and store data-- using AutoLISP, values can be stored in user-defined variables and system variables. User-defined variables are defined and values are assigned to them using the setq function. As you previously saw, an exclamation point in front of the variable's name can be used to retrieve its value at the command prompt. When using the variable in an AutoLISP statement, nothing extra needs to be done.

      System variables are defined by AutoCAD LT and typically are used to store and access drawing and application settings. The value of a system variable can be returned using the getvar function, while the setvar function is used to assign a valid value. Each system variable is defined to store a specific type of data, while a user-defined variable can store any type of data. I discuss some of the data types AutoLISP supports in a little bit.

      The setq function, which assigns a value to a user-defined variable, has two arguments. The first argument is the name of the variable to define and assign a value to, and the second argument is the value to be assigned. The variable name isn't a string value. So there is no need to surround it with double quotation marks.

      Here are some examples of the setq function. The first example defines a variable named dRadius and assigns it a numeric value of 1.25. The second example defines a variable named strEvent with the string value of AU 2023. The final example shows that it is possible to define and assign values to multiple variables in a single setq statement.

      As a reminder, an exclamation point is used to return the value of a user-defined variable at the command prompt, but isn't needed when using a variable in an AutoLISP statement.

      The getvar and setvar functions are used when working with system variables. getvar expects a single string value, which is a system variable name surrounded by double quotation marks. This, the value returned, is the system variable's current value. The setvar function expects two values, the name of a system variable and the value of an expected data type to be assigned to the variable.

      Here, the first example gets the current value of the OSMODE system variable with the getvar function and assigns that variable to a user-defined variable named nOSMODE using the setq function. The second example assigns a value of 33 to the OSMODE system variable with the setvar function. The value of 33 represents the ENDpoint and INTersection running object snap modes.

      Let's do a quick recap before moving on. So far, you have learned to execute commands with the command function, store and use values with user-defined variables in a setq function, and work with system variables using the getvar and setvar functions.

      To get this far, you also learned the importance of both the open and closing parenthesis, the syntax of AutoLISP functions, how to pass values to AutoLISP functions, and how to convert command sequences to AutoLISP statements. I think that wraps up the things covered to this point. But there are a few more concepts to learn yet, so we should get back to it.

      Each value in AutoLISP is represented by a data type. Most values are numeric values or strings. Numbers can be integers, which are whole numbers, or reals, which are numbers with decimal points. Strings are any value surrounded by double quotation marks.

      Lists are another type of data, which is any number of values between an open and closing parenthesis. This might be a coordinate value, or even an AutoLISP statement itself. The final type of data covered in this session is a symbol, which is a user-defined variable named with the setq function.

      Other data types supported by AutoLISP and not covered in this session are pickset, which represents a selection set of objects, an entity name, a graphical or non-graphical object, such as a line, circle, or layer, subroutine, an AutoLISP-defined function or command, vla-object, an ActiveX COM library object.

      In this demo, you see how to define and assign values to user-defined variables, and then use those variables at the command prompt and in AutoLISP statements. Along with user-defined variables, you will also see how to work with system variables using the getvar and setvar functions.

      I'm going to start this demo off by erasing all objects in the drawing using the command function, of course. Here I'm going to type an exclamation point, and then the variable name rad to see which value it is currently assigned. Nil is returned, which means no value is assigned.

      Now I'm going to assign a value of 3.5 to the variable rad. I can verify the variable has been assigned a value by using the exclamation point. Next, I'm going to assign the coordinate value of 5 comma 2 comma 0 to a variable named pt. With these variables defined, I'm going to first use them at the command prompt with the CIRCLE command.

      Now I'm going to use those same variables in an AutoLISP statement to draw a concentric circle. Continuing on, I'm going to turn off orthomode and object snaps from the status bar, then get and change the values of the system variables associated with those buttons. Since orthomode is off, the getvar function with orthomode returns 0. If 1 is assigned to orthomode with the setvar function, the drafting is enabled. Here the ENDpoint and INTersection object snap modes are being enabled with the setvar function by assigning 33 to OSMODE.

      Define custom functions and commands-- AutoLISP statements can be grouped into functions, which allow those functions to be reused over and over again, making it possible to execute many statements at once by name and to build standardized components to simplify the creation of complex programs. Functions you define can be executed at the command prompt, similar to native AutoCAD LT commands. To define a function or command, you use the defun function.

      The defun function, as I mentioned, is used to define a custom function. The first argument of the defun function is the function name to be defined. This name shouldn't be surrounded by double quotation marks, as it isn't a string. The function name can optionally be prefixed with a c colon. This defines the function can be used similarly to a native AutoCAD LT command.

      You have seen the c colon prefix used several times already, even earlier in this session when we opened the samples.lsp file to identify the commands that could be entered at the command prompt. Open parenthesis backslash closing parenthesis after the function name has a specific use in its purpose as described in the handouts. For now, just know it needs to be there with or without the backslash. After that, you provide the AutoLISP statements to execute when the function is used.

      Here are two examples of functions that are defined as commands. This is indicated by the prefix c colon for the function names HelloWorld and ZP. These two function names can be typed at the command prompt. HelloWorld displays a message box with the text "Hello World!", while ZP restores the previous view.

      Here's an example of a function whose name can't be typed directly at the command prompt by name alone. This type of function is used to build standardized components that can be used across many different programs to reduce complexity. The create-layer function creates a layer in the drawing. This function has two arguments. It expects a name and color value, both as strings.

      In the statement showing the usage of the create-layer function, a layer named NewLayer with a color of 45 would be created in an AutoCAD LT. If the layer already exists, though, the color will be updated to 45. In this demo, you see how to define two functions that can be entered at the command prompt. The first function creates concentric circles, while the second zooms to the extents of the drawing.

      AutoLISP functions can be defined. So their names can be entered at the command prompt. If not defined in AutoCAD LT, it lets you know that the command is unknown by a message in the command line window, or it not being listed in the autocomplete list.

      Functions are defined using the defun function, and those that can be entered at the command prompt by name must be prefixed with c colon. Here the function named C2 is being defined, which will allow for the drawing of concentric circles. The next function being defined is named ZX and will allow you to zoom to the extents of the drawing.

      Now, with the two functions defined, let's give them a try. Now that you know how to write your own AutoLISP statements and enter them at the command prompt, the last thing to learn is how to store those statements in a LSP file so they can be loaded and reused in any drawing.

      Store AutoLISP statements and files-- retyping AutoLISP statements at the command prompt is great for learning AutoLISP, but less so when you want to be productive with AutoLISP. AutoLISP statements can be stored in a LSP file to make them reusable across many drawings. LSP files can be ASCII or Unicode in format, which is often dependent on the text strings you need to work with.

      You can create and modify LSP files using Notepad, which was shown earlier while identifying commands in an LSP file. Additionally, Visual Studio Code can be used with the AutoCAD AutoLISP extension to create and modify LSP files. In addition to AutoLISP statements, an LSP file can contain comments. Comments are used to provide information about a file, a program, or even statement. Comments begin with a semicolon, and after the semicolon on the same line, it's ignored.

      Comments can also be defined as blocks. Anything within a comment block is ignored. A comment block starts with a semicolon vertical pipe and ends with a vertical pipe semicolon and can span multiple lines. Here are some examples of comments-- single-line comment, inline comment after an AutoLISP statement, and as a comment block.

      In this demo, you see how to create an LSP file and add AutoLISP statements and comments. Once the LSP file has been created, it is then loaded into AutoCAD LT, where some of the defined commands are used. An LSP file can be created with Notepad, similar to creating a text file.

      Once the file has been created, you can enter the comments and AutoLISP statements to be stored in the file. After your AutoLISP statements have been added and the LSP file saved, the file can be loaded into AutoCAD LT. With the LSP file loaded, you can then use the functions and commands defined in the loaded file.

      In this session, you learned how to use, manage, and write AutoLISP statements and files. As part of this, you learned about the five main AutoLISP functions that you should know to get started, those being command, which executes an AutoCAD LT command, setq, which assigns a value to a user-defined variable, setvar, which assigns a value to a system variable, getvar, which retrieves the current value of a system variable, and defun, which creates a user-defined function or command.

      Redefine native commands through AutoLISP-- using AutoLISP, AutoCAD LT commands can be redefined. Redefining a command allows you to implement a custom version of a command and disable the command under normal usage. For example, you could modify the explode command to not allow it to explode dimensions and blocks, or maybe you want to change the save QSAVE commands so they perform a purge before saving the drawing.

      This is done in two steps. First, the command is undefined using the undefined command. Secondly, the new version of the command is defined using the defun function. When a command is undefined, AutoCAD LT is unaware of its existence. This is seen, or for that matter, not seen in the autocomplete list as well by an unknown command message if you try to use the command at the command prompt.

      To use the native version of a command or one that has only been undefined, you prefix the command name with a period. This helps AutoCAD LT remember that the command does exist and to use its standard and not the custom version of the command.

      Here's an example of undefining and redefining the save command. The save command is first undefined using the ._undefine command, which is prefixed with a period, because it is possible to undefine the undefined command.

      The custom version of the save command displays the message Custom Save before purging the drawing and saving changes using the standard version of the save command, because it is prefixed with a period. -purge is also prefixed with a period to ensure its standard version is used as well.

      Here's what the Custom Save command looks like after being used in AutoCAD LT. Notice after I issue save, the message Custom Save appears, and then -purge is executed immediately after that. While it's not shown in the image here, the save command is also executed as well, because we want to save the drawing, obviously, as well.

      In this demo, you see how to undefine a command and then implement a custom version of that command. Here I'm going to show how to undefine the save command, and then show the resulting behavior in AutoCAD LT. First, let's make sure save is not undefined. You can see it's not as it appears in the autocomplete list.

      Using the undefine command, I can undefine save. Now when I type save, it no longer appears in the autocomplete list. Back in my LSP file, I'm going to add statements to undefined, and then I'm going to define a custom version of the save command.

      With the LSP file saved, I'm going to reload it in AutoCAD LT. Now I can try the custom save command. Notice when save is used, purge was also executed.

      Where to get more information on AutoLISP-- you can find information on AutoLISP by looking at past and currently available AU sessions, the Developer and Customization Guides in the AutoCAD online help, and Have You Tried and Try articles that can also be found in the AutoCAD LT online help. Additionally, discussion forums, internet searches, and books can also be great resources to learn about advanced topics and get questions answered by fellow peers.

      Final thoughts-- congratulations, you're now a programmer! Go forth and bring chaos. I'm sorry. I mean make sure your fellow drafters are more productive so they may focus on designing, rather than just doing. Sorry. I got ahead of myself there.

      General customization in AutoLISP programming can help enhance your productivity and improve your existing workflows in AutoCAD LT. Like the concept of parallel universes, the possibilities of customization and programming are virtually endless, and many mysteries are awaiting you to be discovered.

      If you have any questions, please reach out to me using my email address, or X, formerly Twitter, account. Thank you for watching this session.