Loading AutoLISP Files.
One of the most important things to remember about loading AutoLisp
Routines is to ensure that your Lisp files and any support files (i.e DCL
Files; DAT Files; etc) are in your AutoCad search path. (I dedicate a
directory to all my Lisp files and relevant support files.
There are numerous ways of loading AutoLisp Files :
Command Line Loading.
The simplest is from the AutoCad command line.
The syntax for loading AutoLisp files is :
The.lsp extension is not required.
The following code samples are one way of loading AutoLisp files from a
Pull Down Menu's :
T_Steel [Steel Menu]
T_Beams [Drawing Setup]^C^C^P+
(cond ((null C:DDSTEEL) (prompt "Please Wait...")(load "DDSTEEL")))
TB_DDSTEEL [_Button("Steel", "STEEL.bmp",
(cond ((null C:ddsteel) (prompt "Please Wait...")(load "ddsteel")))
This method of loading Lisp files first checks to see if the routine is
already loaded. If it is, it runs the routine. If it is not, it first
loads the routine, then runs it. Clever Hey...
The Acad.Lsp file is a useful way of loading a library of AutoLisp
Each time you start a drawing AutoCad searches the library path for an
Acad.Lsp file. If it finds one, it loads the file into memory.
You could use the normal load function (load "filename") in
your Acad.Lsp file but if an error occurs whilst attempting to load one of
your routines, the remainder of the file is ignored and is not loaded.
Therefore, you must use the on failure argument with the load
(load "Lispfile1" "\nLispfile1 not
(load "Lispfile2" "\nLispfile2 not loaded")
(load "Lispfile3" "\nLispfile3 not loaded")
The .MNL File
The other type of file that AutoCad loads automatically is the .MNL
If you have a partial menu file it can also have it's own .MNL file.
Just remember that the .MNL file must have exactly the same name as your
partial menu file. (except for the .MNL extension, of course.)
You can load Lisp files from this file using the load function exactly the
same as you did in the Acad.Lsp file.
When you automatically load a command from your Acad.Lsp file (or a .MNL
file) the commands definition consumes your systems resources whether you
actually use the command or not. The Autoload function makes a command
available without loading the entire routine into memory.
(Autoload "Utils" '("Utils1"
(Autoload "DDSteel" '("DDSteel"))
This would automatically load the commands Utils1, Utils2 and Utils3
from the Utils.Lsp file and DDSteel from the DDSteel.Lsp file.
If the user defined function S::Startup is included in the Acad.lsp or
a .MNL file,
it is called when you enter a new drawing or open an existing drawing.
e.g. Say that you wanted to override the standard AutoCad LINE and COPY
commands with versions of your own, your Acad.Lsp file would something
like this :
(defun C:LINE ()
(defun C:COPY ()
(defun S::Startup ()
(command "Undefine" "LINE")
(command "Undefine" "COPY")
Before the drawing is initialised, new definitions for LINE and COPY
are defined. After the drawing is initialised, the S::Startup function is
called and the standard definitions of LINE and COPY are undefined.