How to use acad.lsp and acaddoc.lsp

by Will on October 19, 2011

Lisp is a very useful part of the AutoCAD® application, and one of the first things its good for you to know is how acad.lsp and acaddoc.lsp work. These two lisp files are automatically executed when certain conditions occur in AutoCAD®.

acad.lsp

Firstly, acad.lsp is by default executed when AutoCAD® first boots up. Therefore, this will run once only. Because of this it is a great place to put startup procedures, or things that you want to do to initialise AutoCAD®. For example, I have mapped commands to various key combinations under my left hand, including SS, DD and DA. The problem is, these are existing built in commands to AutoCAD®. The solution for me was to use the UNDEFINE command to remove the default commands from AutoCAD®, which would then allow my own customisations in acad.pgp to take priority. And acad.lsp is a great place to run these commands, like so:

(command “undefine” “ss”)
(command “undefine” “dd”)
(command “undefine” “ad”)

For those new to lisp, the lisp command at work here is “command”, which basically allows you to invoke any AutoCAD® command from lisp. The text provided in quotes will be executed as if you had entered them into the AutoCAD® command line.

acaddoc.lsp

So how does acaddoc.lsp differ? As the name suggests, this has something to do with documents. In fact this lisp file is run every time a document is opened. Therefore this is the perfect place to do anything that is specific to the drawing you are working on. For example, I have a few system variables that I like to be set a certain way. Annoyingly they are drawing specific, but using acaddoc.lsp we can set them to whatever we want when the drawing is opened:

; SKETCH produces polylines
(setvar “SKPOLY” 1)
; suppress “Would you like to convert to a polyline prompt”
(setvar “PEDITACCEPT” 1)
; set linetypes to be continuous on polylines
(setvar “PLINEGEN” 1)

Here are a few. For those learning lisp, the”setvar” lisp command tells AutoCAD® to set the value of a system variable (pretty obvious really!). Again, the arguments passed to it will have to correspond with how you’d enter them into the command line normally.

Where to save acad.lsp and acaddoc.lsp

The location of where to save acad.lsp or acaddoc.lsp depends on what you want to achieve, but it will only be loaded if it is found in one of your support paths, as specified in Options > Files > Support File Search Path. In the beginning, I assumed you could have many of these files in multiple support paths, but AutoCAD® will only load one. If there are many, AutoCAD® will load the first one that it finds in the order specified in your support paths. Support paths higher on the list will be searched before lower ones.

If you are working in a team that use several of the same lisp functions, a good idea is to place acad.lsp and acaddoc.lsp in some networked location, and add that location to you list of support paths. This is a much more manageable way, rather than trying to keep multiple files up to date on many computers. In order for these to run of course, it will have to be the first acad.lsp or acaddoc.lsp file that it finds, so you may have to rename or delete old versions of acad.lsp/acaddoc.lsp that already exist in local support paths.

So hopefully this has helped to understand acad.lsp and acaddoc.lsp. It’s pretty simple really, but knowing that little bit of extra detail can help to get things working the way that you want.

As always, I’d like to encourage newcomers to subscribe below, and you’ll get an email every time I write something new. If I don’t write anything, then you’ll get no email!

Will

Enter Your Mail Address

Be Sociable, Share!

{ 6 comments… read them below or add one }

Randy L Rickman November 29, 2011 at 5:59 pm

I am using Autocad 2004 ~ dont have an acaddoc.lsp file to use. Can you tell me where I can download a virus free acaddoc.lsp file to use?

Thank you so much

RLRickman

Reply

Will November 30, 2011 at 10:22 am

You don’t need to use an existing one. By default, acaddoc.lsp contains nothing. So simply create an empty file using Notepad.exe, and away you go!

Reply

Renato January 12, 2012 at 4:40 pm

Hi there,

It seems that I have a lot of acaddoc.lsp files in the server. Should I be worried? Is there any free anti-virus for cleaning the ***.lsp files???

Everything I have read online is using DOS, I think, for cleaning it but I don’t understand nothing about that.

Thank you

Reply

Will January 16, 2012 at 8:10 am

Yes, you should be a bit worried.

There is a acaddoc.lsp virus that self-duplicates going around. Get in touch with your MIS department (if you have one) and ask them to add this to their virus scanner (assuming they use one!). If not, I believe there is a fix called KillWorm.lsp, though you’ll have to find it as this is purely from memory.

Will

Reply

Chris January 18, 2012 at 11:22 pm

I’m having trouble loading my ACADDOC at a new company that runs Autodesk Product Design Suite Ultimate 2012. May ACADDOC has always worked fine on other versions (2010 and below) of AutoCAD, but for some reason it’s not loading up in 2012.

For starters, everything is in the root folder for AutoCAD Mechanical, including all of the AutoCAD stuff; there is no separate folder for AutoCAD under the program files folder as it is installed by the suite. In other words, Mechanical is what installs from the suite, AutoCAD installs with it; just in no separate folder; either way this should not matter since both applications are looking to the same installed folder.

The one thing I have noticed is that the root folder of AutoCAD Mechanical does come with its own ACADDOC now, and it looks different than anything I’m use to seeing. I’ve never had a problem getting the DOC to load before, so this has got me pretty stumped at the moment.

Reply

Will January 30, 2012 at 10:03 am

If there is another acaddoc.lsp, then only one of the files will be loaded. They’re loaded in order of the support paths, so I’d try checking that first.

Reply

Leave a Comment

Previous post:

Next post: