AutoLISP Programming Basics | Learn How to Supercharge AutoCAD Customization

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
customizing AutoCAD using the lisp programming language is a great way for users to increase their productivity whether you use them to simplify using certain commands or use it to automate large portions of your project lisp can be a great way to speed up your drafting for the first time in 2024 AutoCAD LT has added the ability to load and use Auto list routines this is great news for old school CAD users like myself so to celebrate this episode covers the basics of creating simple Auto list routines yourself [Music] thank you Auto lisp is a version of the lisp programming language that can directly interact with AutoCAD of the four different methods of programming AutoCAD Auto lisp visual lisp object arcs and Visual Basic it's possibly the easiest method to use to start making custom commands in AutoCAD unlike the other options it only requires a text editor all of those routines can be found and downloaded online in many different places popular sites like afrolisp CAD corner and CAD Studio have several hundred routines you can download and use sadly many of these routines were written for older versions of AutoCAD changes to the AutoCAD API can render these programs inoperable in modern versions of AutoCAD in a future video I will detail how to fix common problems with these downloaded lisper teams for now let's just tackle the basics [Music] in the programming World a simple hello world is generally how most are introduced to a language in AutoCAD though a hello world example is pretty useless we will instead work on a simple useful example command stacking we have another video on how to add new aliases to AutoCAD commands see the link in the description below but these only work for making the command name shorter to add more complex options you need to program it to do so all AutoCAD commands have command line options that allow you to change a way a command Works in normal operation one has to type the command press enter type the command line option and press enter again there are other ways to use command light options clicking on them right clicking Etc but for this video we will focus on typing when trying to stack command line options together it pays to go to AutoCAD and use the command several times typing it into the command line you'll want to write down the steps it takes to make the command do as you wish if you type the command in a dialog box pops up try adding a dash or a DOT before the command name this activates an older version of that command that only uses the command line the command line only version is the one we want to use if you want to use zoom extints using the keyboard one has to type Zoom enter and E enter this is clearly too many enters if we write that commanded list we can remove one of them this may not seem like a huge savings but believe me they definitely add up [Music] we will Begin by starting a new document in Notepad we'll start by typing in the steps we need to remember Zoom all auto list commands start with an open parenthesis and the command D fund this lets AutoCAD know we are naming a new command adding C colon Ze parentheses means we are naming the new command as Ze and the blank parentheses indicate we aren't passing it any parameters next we add a new line of code to make it cleaner We'll add a tab to this line to show that it's inside the command itself unlike say python Auto list doesn't need the tabs it's only to make it easier for us to read inside a new set of parentheses we add something from the AutoCAD API command quote Zoom quote e the command part lets AutoCAD know we're calling a regular AutoCAD command in this case Zoom anything in quotes will be typed for you followed by the enter key after entering the zoom command we want AutoCAD to use the extents option so we add an e that's it well mostly we now need to make sure the command closes cleanly to do this we add one line to our code print C this simply adds a blank line in our command line after the command has been executed finally we need to close all our parentheses since we started with an open parenthesis right before D fund we simply need to close it like this white space doesn't actually matter here we can also write the routine like this for short routines this can be great but the expanded version can be much easier to read we can now save the file making sure to use save as selecting the all files option and naming it with the dot LSP file type to load it into AutoCAD go to the manage Tab and choose the command load application you can also type appload browse to the file you created and AutoCAD will add a new command Ze which will accomplish our simple task with less effort hooray now that you've seen an example let's get a little more generalized every command in lisp is surrounded by parentheses like this just doing this isn't super interesting so most commands can take in more information also inside of parentheses like this the problem is this can also take input like that it's a good idea when you're starting out to try and put each command on its own line and use the Tab Key to line up arguments to better show the program structure if it's really simple it can be easier to read if we change up the format a bit but generally that's the way it's put together you now officially know enough lisp to tell a programmer lisp sure does have a lot of parentheses and they will laugh true story [Music] in our previous example we're calling three commands the top line is required for all lisp routines it names the command we're about to write all it's doing is telling AutoCAD everything inside these parentheses is called Ze just assume you always have to do this it needs to be unique you can't load another command called Ze and expect AutoCAD to know which one you want it will always execute the last one you loaded the middle line is where the actual work is done we're simply typing in an AutoCAD command exactly how you would in the program do not use an alias for this as users can easily change their aliases and then your program wouldn't work each item in quotes is entered into the AutoCAD command line is the equivalent of Simply typing Zoom enter e enter the last line is generally required for the end of a lisp in AutoCAD a command has to return control of the command line back to the user this is done by printing a blank line on the command line again just assume you always have to do this now that you've seen the basics here are a few examples from one of my main list routines one called quick key here I've defined several shortcuts that I use regularly you will see that I've defined several commands in a single file you can Define as many routines that you want in a single file they simply get their own defund code to separate them out I've also used a semicolon to add comments that help me remember what I was trying to do when I first wrote it comments are your friend some of the examples introduce a new option in the command function often in AutoCAD you need to click on the screen or enter a number in the middle of a command pause allows you to take a break from the list routine and let the user Drive I've always been disappointed in how the old break it point doesn't give you any feedback and let you know it's actually done something so you'll see in the BB command I added a note using the prompt command that is displayed in the command line when the command is finished as you get into more complicated routines though it can become really easy to lose track of how many parentheses you're supposed to have and where programming text editors often have the tools to track and color your code to make it much easier to debug in later episodes we'll explore more advanced routines and parentheses can get all over the place and you scream inside a little in the next episode in this series we'll take a look at my three favorite notepad plus plus Sublime Text and visual studio code and see how to set them up for now start paying attention to how you use AutoCAD and start to see where you can remove key presses from your own projects the new AI assistant in AutoCAD 2024 will also pop up recommendations and are a good place to discover efficiency improvements for the things you do daily I've put a link to the auto lisp API in the description you find this helpful click the link button do you have some simple routines that you use and would like to share them please do so in the comments click subscribe if you're liking what you see here and want to see more of it and if you're interested in our AutoCAD Revit inventor Fusion 360 microstation civil 3D SketchUp or 3ds Max classes check us out and Atkins techconsulting.com as always I'm David and happy Academy [Music]
Info
Channel: ATC CAD
Views: 10,732
Rating: undefined out of 5
Keywords:
Id: JS5ThafEpFs
Channel Id: undefined
Length: 10min 11sec (611 seconds)
Published: Mon Jul 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.