05 February 2008
Setting system variables at startup          

How do you set system variables at drawing startup in AutoCAD? This can be answered in a variety of ways, some right and others wrong. I'm going to explain the right way based on Autodesk recommendations.

First off, what do you want to set and where is this setting stored? Look up the system variable in HELP and find out if it's stored in the drawing, or the registry or not at all.

If it's stored in the drawing, then consider whether or not you really want to change this at startup. While you are thinking about that, open you template drawing(s) and make the change there. Now at least your new drawings will be set the way you want.

Now why would you not want to change a drawing-saved system variable at startup? Have you ever opened a drawing, and not changed anything, then tried to close it and you were prompted to save? This is why. If you have startup code that changes a drawing saved system variable, the drawing database is modified and you will be prompted to save the drawing, even if you have not changed it in any other way.

NOTE: DBMOD is a system variable that is set to zero (0) each time a drawing is opened. If anything is changed, the value of DBMOD is not zero (0) any longer. When you go to close the drawing, if the value of DBMOD is not zero (0), then AutoCAD will prompt you to save.

Before we get started, let's cover a couple of "rules".

  1. Make sure ACADLSPASDOC is set to 0. This is the default setting.
  2. A file called "ACAD.LSP" is loaded once when AutoCAD starts. Any lisp code in this file is loaded into memory or executed at this time.
  3. A file called "ACADDOC.LSP" is loaded each time a drawing is loaded, including when AutoCAD is first started. Lisp code from this file is loaded each time a drawing is loaded.
  4. For either file above, AutoCAD will load the first file it finds and only the first one.
  5. AutoCAD will search the support file search path, in the order of the paths.

Things you might want to put in "acad.lsp" include system variables that are not saved or saved in the registry such as "expert", "isavebak", "and savetime"

Things you might want to put in "acaddoc.lsp" include drawing saved system variables (although I personally avoid this), and other lisp code that need to be defined in each drawing

Once you have determined which file to edit/create, here is how to do it.

  1. Open AutoCAD.
  2. Paste one of the following lisp functions (in blue) to the command line and press enter
  3. (findfile "acad.lsp") -or- (findfile "acaddoc.lsp")
  4. If a filename is returned, open this file in Notepad or use the VLIDE (Visual Lisp interactive development environment) to open this file. Go to step 5.
  5. If nil is returned, open a new file in Notepad or the VLIDE. Save the file using the correct name and make sure you save it to a directory that is in your support file search path. Close this file, and repeat step 2 and 3 to make sure AutoCAD can find this new file.

Now you have the right file open. You just need to add a bit of lisp code to set the variables to your liking, using the (setvar) function. Here is a few examples:

(setvar "EXPERT" 3)

(setvar "EDGEMODE" 1)

(setvar "OSMODE" 20)

The case of the letters is not important. But the value(s) that you are trying to set are important. In the first example, we are trying to set the system variable EXPERT to 3, which is valid. But if we try to set it to 8, it will fail.

Valid settings for each system variable are found in HELP.

Many system variables are stored as a bitcode using the sum of individual values. OSMODE is one of these. If you look in HELP, you will see that the setting for QUA object snap is 16 and the setting for NOD object snap is 4. If you add these two together, you get 20. If you wanted to set END and MID you would add 3 more and make the setting 23.

Remember, this is only addressing the changing of system variables. Next time, we'll cover adding more sophisticated lisp code to the startup files.

Note: Do not modify the files named "acad200?.lsp" or "acad200?doc.lsp". These files are located in the stock AutoCAD support directory, but these files are used by AutoCAD. If you place your startup code in these files it will work, but these files may be overwritten by a repair, reinstall, or application of a service pack. There is NO reason to use these files. Use "acad.lsp" and/or "acaddoc.lsp". These are user defined and controlled files.

Reference Links:

Labels: ,

PermaLink       Posted 2/05/2008 12:45:00 PM     

Post a comment