Autocad Customization – Set System Variables

Published on October 8, 2012

Written by Eric Gates.

Using acad.lsp and acaddoc.lsp to set application variables, and drawing variables

A good place to start with AutoCAD customization is with the basic use of Lisp. Which means first knowing how acad.lsp and acaddoc.lsp work, and where these files should be located.

When AutoCAD starts, it searches the support file search path for an acad.lsp file.

Autocad Training

If the file is found it reads the contents and loads it in memory. By default the acad.lsp file is only read once at the application start-up.

Autocad Training

The ACADLSPASDOC is a system variable to control when the acad.lsp gets loaded.  The default setting is set to 0. Setting it to 1, will cause the acad.lsp file to be reloaded each time a drawing is opened during a session.

Autocad Training

Create an acad.lsp file using a basic text editor and place it into one of the Support File Search Path locations.  Remember it will read the first acad.lsp file it comes to in the list of paths, so one path could be a location on a server that is shared by all users.  Since the acad.lsp will run at start-up, you may want to use it to set application based variable, create or load custom shortcut keys and load other custom routines.

Next, is the acaddoc.lsp file.  If there is an acaddoc.lsp file found in the Support Search Path when a drawing is opened, it will be loaded each time. The ACADLSPASDOC variable does not apply to the acaddoc.lsp file.  This means that this file should most commonly be used to set drawing specific variables.  Just like the Acad.lsp, the path list is searched in priority of how they are listed, from top to bottom, so if more than one acaddoc.lsp exist in different path locations, the first one found will be the one that gets loaded.

The acaddoc.lsp file can be created with a basic text editor.

Example of a basic acad.lsp.

(Defun C:C   () (command "COPY")(Princ))
(setenv "MaxHatch" "1000000")
(setvar "FILEDIA" 1)
(setvar "ISAVEBAK" 0)
(setvar "LOGFILEMODE" 0)
(setvar "PEDITACCEPT" 1)
(setvar "MAXSORT" 5000)
(setvar "PICKFIRST" 1)
(setvar "XLOADCTL" 0)
(setvar "XREFTYPE" 1)

 

Example of a basic acaddoc.lsp

S::STARTUP
(command "-scalelistedit" "r" "y" "e")(print)
(command "wscurrent" "3D Basics")
(command "FILEDIA" 1)(print)
(command "UCSFOLLOW" 0)(print)
(command "PLOTOFFSET" 1)(print)
(command "INSUNITS" 0)(print)
(command "UCSICON" "N")(print)
(command "LAYERNOTIFY" 0)(print)
(command "SSMSHEETSTATUS" 1)(print)
(command "MSLTSCALE" 1)(print)
(princ "\nGENERAL VARIABLE SETTINGS loaded!")(print)

 

The acad.lsp and acaddoc.lsp file are each loaded into memory before the drawing is completely initialized so in order to make sure the command function will work, the function S::STARTUP is included so all the commands after it are called once a new drawing is created or an existing drawing is opened. You may include a definition of S::STARTUP in any LISP file to perform any setup operations. There are limits and setting override possibilities that are not further addressed in this post.


Tags: , ,
Like this article? Share it!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Privacy Policy