Back

AutoCAD LT Gets the Power of AutoLISP

Since the theme of this issue is “What’s New,” I’m excited to tell you about the inclusion of AutoLISP in the AutoCAD LT 2024 release. How’s that for something new? I’ll wait while you pick your chin up off the floor.

What a world of possibilities this opens up for the LT user. Now, they can extend the capabilities of their program of choice without being restricted. Oh, think of the defun they will have (that’s a little Lisp humor… welcome to the club, LT users). And I’m not talking just old-fashioned raw AutoLISP either. ActiveX Automation is included as well, so you’ll also have access to the COM library and (nearly) the full functionality of Visual Lisp.

With LT 2024, you’ll be able to automate repetitive tasks, create custom short commands, analyze drawing data, and fix things on the fly. The power you now wield is only constrained by your imagination.

Not So Fast, My Friend

Well, kind of. You see, there are a few limitations and some things you don’t get. First and foremost is the VLIDE (Visual Lisp Integrated Development Environment). That’s the editing and debugging tool integrated into full AutoCAD and used by most AutoLISP programmers to develop, edit, and debug their code. And, since there’s no VLIDE, there’s no Visual Studio either. So, if you want to write your own AutoLISP code, you’ll be relegated to a text editor such as Windows® Notepad.

What else won’t you get? Remember I said you’d (nearly) get the full functionality of Visual Lisp? You can do a lot with ActiveX and Visual Lisp, but you can’t do things that LT doesn’t support. So, while an AutoCAD user can use Visual Lisp to create, modify and manipulate 3D objects, LT doesn’t support 3D, so that code won’t work. The same would go for anything that LT doesn’t have, like constraints, profiles, or connecting with external applications such as Excel®.

But Visual Lisp has self-awareness, so any programming tasks requiring access to the AutoCAD object model should be fine. During the Beta phase, I tested it to see what would happen. Honestly, I expected the call to (vlax-get-acad-object) not to work in LT. Good news, it does. Now, I haven’t gone through every line of code in my library, but nothing has broken for me yet. Of course, your mileage may vary.

An AutoLISP Primer

But I’m getting a bit ahead of myself. The odds are that if you’re an LT user, you don’t know enough about AutoLISP even to understand what I just said. That’s OK; we all started with zero AutoLISP knowledge. But you’re probably at least aware of it, and you know that it’s the most common way to extend AutoCAD’s (and now LT’s) functionality.

So how do you get started using this bright, shiny, new toy that’s now in LT? Let’s start with some of the basics. First of all, AutoLISP is a dialect of the second oldest programming language that’s still in use today (Fortran wins by a year). It was added to AutoCAD back in Version 2.18 in 1986, and the user base immediately embraced it.

Why? Well, one reason was that it was relatively easy for non-programmers to read and use. Unlike other languages, it didn’t require any memory allocation, there was no declaration of data types, and you didn’t even have to compile your code. In fact, its interpreter was built right into AutoCAD so that you could run expressions right from the Command Line.

But here’s the kicker… since you don’t have the VLIDE in LT and you don’t have any previous experience with AutoLISP, how do you get started? As a non-programmer, there are a few things you need to know. One is that you’ll get the code you need from the internet. You see, we AutoLISP programmers love to post our code for others. It might just be a “look what I did” thing, or they just want to share. The truth is that it’s everywhere. All you need are some good search skills to find it. I’ve always said that if you have a great idea for a Lisp routine, you’re not the first to have had it. And more than likely, it is out there on the internet somewhere.

This is a good time to mention file types. Typically, the code you find will be in the form of a text file with an LSP extension. You may find raw code posted that you’ll need to copy and paste. If so, use a plain text word editor such as Notepad (or better yet Notepad++), as Lisp code doesn’t react well to the formatting you’ll get in a word processor. Just paste it into a blank text document and save it with an LSP extension.

You may also find code with an extension of VLX or FAS. These are compiled formats and will be harder for you to use because you can’t open and read them. More on that in a minute.

Loading Your Code

OK, sounds good. What next? You’ve found your code. It seems to come from a reliable source (the AUGI forums come to mind), but now what? You’ll need to know how to load it into LT, and once loaded, you’ll need to know how to run it.

Loading your code is pretty easy. For a beginner, I favor the drag-and-drop method. That’s right, you can just drag a Lisp file right into the drawing editor, and the code will load. You can also use the APPLOAD command (the same one you’ll find in AutoCAD) to navigate to and load your Lisp file. If you’re going to be using a program often, there’s something called the Startup Suite that you can find in the APPLOAD dialog. Put your file in there, and it will automatically load whenever you open a file.

There’s another way to load your code with every drawing, but it also lets you run those functions (or individual statements). I like to call it a CAD Manager’s secret weapon, and over in AutoCAD, it’s named ACADDOC.lsp. It was the first thing I tested in LT 24, and as I expected, it did not work. But when I renamed it with the LT in place (acadLTdoc.lsp), it worked!

All you need to do is make sure it’s in a folder that LT can see—something in the support file search path section. I chose to use C:\Program Files\Autodesk\AutoCAD LT 2024\Support\ during my testing. Typically, I have a custom folder for all my AutoLISP code and add that folder to the search paths. Whichever way you choose, make sure its folder is also on the Trusted Locations list.

Note: If you’re already aware of ACADDOC.lsp, you’re no doubt aware of ACAD.lsp too. The same name game works with that as well.

ACADLTDOC.lsp is a great place to control your LT environment. Maybe you have a set of running Osnaps that you prefer. Make sure they’re always set the way you like them by adding (setvar “osmode” 695) to your ACADLTDOC.lsp file. Before you do, make sure your settings are correct, then type OSMODE into the command line to see what your number is. I’m a 695 kind of guy. I’ll have dozens of lines like this to control everything from ATTDIA to XLOADCTL.

Understanding Your Code

You’ve scoured the internet, found some great code, and know how to load it, but you may not know how to run it. Unless the programmer was super-friendly and included a prompt about what to type in, you’ll have to open the file to find out what you type in to run it.

It’s not as daunting as it sounds. Open the LSP file with a basic text editor. You’re looking for the AutoLISP function DEFUN, followed by a C: and then some other word. So, something like this:

(defun c:someotherword …

Don’t worry about capitalization; that’s just a matter of personal style. It’s the word after the C: that will invoke your code. While the statement you’re looking for is typically at the top of the file, it could be anywhere. I suggest a text search for “defun c:” Please note that there may be multiple DEFUNs in your file.

If you’re like most of us, you may start to experiment with your new toy. You know, you’ll change a few things and try it out. If you are interested in learning more about AutoLISP, there are some tried and trusted resources out there for you. I’ll include some links to resources at the end of this article, but some good ones are AfraLISP, CADTutor, and the AutoLISP Tutorial from Autodesk.

A New Resource

If AutoLISP was added to AutoCAD LT 2023 and not ‘24, I would not need to write the following, but… here we are. I’m talking Artificial Intelligence. You’ve undoubtedly heard about these AI chat sites that have popped up this year. Just ask one of them to write you some code!

I went to one of the more well-known sites and asked it the following question:

Within seconds, I was presented with the following.

Quick Quiz: After it loads, what would you type in to run this code?

Wow! What a world. Now that’s what I call easy programmin’, but… (there’s always one of those, isn’t there?) a word of caution. Although the code looks great, it doesn’t work. The AI messed up the parenthesis matching on the while loop. Oops… rookie mistake. Fortunately, I’m not a rookie, and I was able to fix it quickly, but chances are, you’re not, so proceed with caution. I also have the advantage of using VLIDE to debug it quickly. You probably won’t.

Having said that, I’m writing this before the new LT release date. As fast as this technology is changing, it might be perfected by the time this issue is published (or it may have taken over and become our overlord). In the spirit of full disclosure, I asked the same thing five times. I got usable code once. I also got five different ways to write it.

Summing it up

I hope I’ve given you some things to think about. If you had told me this time last year (or just months ago) that I would be writing about using AutoLISP in LT and instructing you to use AI chat sites to help you, I would have thought you were crazy.

But here we are, and AutoCAD LT now has AutoLISP capabilities. If you’re an LT user, I hope you’re excited because you should be. And, since you’re a faithful AUGIWORLD reader, you know that there are plenty of your co-members who are more than happy to help you along the way.

Resources

Forums and Discussion Groups.

The AUGI Forums, and the AutoLISP Forum

https://forums.augi.com/

https://forums.augi.com/forumdisplay.php?91-AutoLISP

The Autodesk Discussion Group

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130

Tutorials and Learning

Autodesk Customization Guides

https://help.autodesk.com/view/OARX/2024/ENU/

Autodesk Help System AutoLISP Functions Reference

https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-4CEE5072-8817-4920-8A2D-7060F5E16547

Autodesk Getting Started Tutorial

https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-C64046FA-CD9E-4B38-9967-A501119E4A62

AfraLISP

https://www.afralisp.net/

CADTutor

https://www.cadtutor.net/tutorials/autolisp/quick-start.php

Free Downloads

Lee-Mac Programming

http://www.lee-mac.com/

JTB World

https://jtbworld.com/autolisp-visual-lisp

AfraLISP

https://www.afralisp.net/download/

Appears in these Categories

Back