05 Jan 2011 11 Comments
Auto-Loading AutoCAD LISP Utilities – by Aaron Werning
Since AutoCAD’s loading of functions operates with the premise of “last loaded wins” (i.e. if you have 2 utilities loading with the exact same function name, the last one to be loaded will be the one AutoCAD will recognize when executing a utility), it is important to understand a few things about how and where AutoCAD looks for files to load. When you open a new or existing drawing, AutoCAD is pre-programmed to look for certain support files in a certain order.
Autodesk’s “AutoCAD” STARTUP FILE LOADING ORDER:
1) acad2011.lsp (AutoCAD file)
2) acad.lsp (User file – only loaded once at AutoCAD 2011 startup, unless ACADLSPASDOC=1)
3) acad2011doc.lsp (AutoCAD file)
4) acaddoc.lsp (User file)
5) custom.mnl (User file)
6) mymenu.mnl (User file)
7) acad.mnl (loaded when “acad.cuix” is loaded)
8) acetmain.mnl (loaded when acetmain.cuix” is loaded-Express Tools)
9) files in the startup suite
10) S::STARTUP Function (may be defined\re-defined in multiple locations)
NOTE: Anything labeled as a “User File” are not files that you will find out of the box.
The acad.lsp and the acaddoc.lsp files are legacy files that still have a use. The difference between the two (besides load order) is the fact that acad.lsp is designed to run only on the first drawing opened in an AutoCAD session (unless ACADLSPASDOC=1), whereas the acaddoc.lsp is designed to run on every drawing that is opened up in a single drawing session. You must create these files and place them somewhere in your support directory structure (found in AutoCAD in the ToolsàOptions dialog on the “Files” tab). The support directory structure is hierarchical, meaning that if an acaddoc.lsp is found under 2 (or more) of the paths in that list, only the one at the highest path in that list will be used.
The custom.mnl and mymenu.mnl files are used only if you have a custom.cuix or mymenu.cuix menu that you have loading. These files would be a good place to put functions that are specific to your user menus so as to keep the entire menu’s functionality in one place.
The Startup Suite is a classic place for the average user to put a library of LISP routines. It is easy to explain how to do it, and it also falls very close to the end of the list so as to ensure that what the user want to use will get loaded near the end. However, if you are a CAD Admin and have set up company wide commands (maybe in the acaddoc.lsp file) that aren’t working for a specific user, this would be your first place to go to make sure they are not overriding the company command with a personal LISP routine.
Lastly, the S::STARTUP is a function that gets run very last after ALL startup files have been loaded. This is an advanced way to make sure a function gets run after the entire drawing has been initialized (you will find that there are certain tasks that cannot be performed while initialization is happening). However, there are things to consider when using this option and it will take a bit of discussion to explain…for next time.
(Auto loading of .NET utilities will also be discussed in the future)




Jan 05, 2011 @ 13:39:02
Thanks Aaron, this is extremely helpful!
Jan 05, 2011 @ 13:41:38
Great post Aaron. The LISP newbie out there will like this tidbit. Thanks for sharing you knowledge with the DT.com community. (You can pay me later. lol)
Jan 05, 2011 @ 13:43:27
Aaron thanks very much. this is invaluable information which is not always easy to find. Looking forward to the next installment.
Jan 05, 2011 @ 14:00:27
Good post Aaron, good information and much needed for the majority of us in the industry.
Jan 05, 2011 @ 15:26:36
Thanks, Aaron. Your post is clear and It’s great to see this laid out in a way that makes sense! As Brian said, I am looking forward to your next installment!
Jan 05, 2011 @ 21:23:53
Great info Aaron! Could you write an article explaining (mapcar ‘(lambda (x) )) for us? Thanks!
Jan 06, 2011 @ 14:15:57
Aaron, I agree with Zortar on the next article. lol
Jan 06, 2011 @ 00:20:01
I have to disagree with the term “legacy” regarding the Acad/AcadDoc.lsp files. Those files are no more a legacy file than the Acad20xx.lsp or Acad20xxDoc.lsp files. As long as AutoLISP/Visual LISP are supported by AutoCAD those files will never be legacy.
Jan 10, 2011 @ 17:43:43
Robert,
What I read in Aaron’s post regarding the term “legacy” is more that they are “something from the past” as opposed to “outdated or discontinued”. I think this is an important distinction for many of us admins who have created autoloading procedures for our companies that have existed for a couple of decades going back to the original ACAD.LSP file. With each new release of AutoCAD, new files that affect the initial loading of company routines are introduced and we to decide if we need to merge the “legacy” files with the new ones or ignore the new ones, etc. Knowing this, I think you will understand the importance of the distinction Aaron is making.
Jan 06, 2011 @ 14:03:00
Thanks for the post Aaron, hoping there is more tidbits to come from you. As always your sharing of knowledge is appreciated.
)
Jan 06, 2011 @ 15:45:24
I would like to take issue with the font and some of the capitalization. I’m also not sure on some of the punctuation.