Automatic Loading of LISP Files

Before a function can be used, the file which contains its code must be loaded using AutoLISP’s (load) function. By combining a series of similar functions into a single file with a .LSP extension, you can create a library of LISP files. For example, if all the code for the BOX1, MIDPT, and TAG functions were stored in one file called CLASS.LSP, you could load all those functions at once by typing:

(load “class”)

Special Files: ACAD.LSP and ACADDOC.LSP

If a group of LISP functions are needed in virtually every drawing session, then they can be loaded automatically each time you start AutoCAD.

The file ACAD.LSP, if it exists, is automatically loaded by AutoLISP when AutoCAD starts. It is available only in the first drawing you open. To have AutoLISP routines available in all drawings that are opened during a session of AutoCAD use the ACADDOC.LSP file.

  • Any AutoLISP expression can be included in the ACAD.LSP file including function definitions and symbol values.
  • These files do not exist by default.
  • Do not modify the ACAD2000.LSP or ACAD2000DOC.LSP files. These files include functions needed by AutoCAD. They are loaded directly before the ACAD.LSP or ACADDOC.LSP files.

Example

A sample ACADDOC.LSP file, this includes the code for DegreesToRadians and then loads three separate LISP files, BOX1.lsp, MIDPT.lsp and TAG.lsp.

See also  why AutoLISP in AutoCAD?

(defun DegreesToRadians (DEGREES)
(* DEGREES (/ PI 180))
)
(load “BOX1”)
(load “MIDPT”)
(load “TAG”)
(princ)

Automatically Loading Menu Functions: ACAD.MNL

Another special file that you can create is the ACAD.MNL. This file of AutoLISP routines loads whenever you load a menu by the name of ACAD. You can also create additional *.MNL files for each partial menu you want to load. Just make sure the file name is the same for both the .MNU and .MNL files.

Example

If you have a partial menu file named PLOTTING.MNU then you would create an additional AutoLISP file call PLOTTING.MNL that would call (load) the AutoLISP routines needed for that menu.

PRACTICE

Create an ACADDOC.LSP file in your class directory that will automatically load the files you now have in TRANSLATION.LSP. We will add more later.

  • The ACADDOC.LSP file must be stored somewhere in the primary search path. You can add the class directory to this path through Options>Files.
Back to top button