Sei sulla pagina 1di 4

Loading AutoLISP Files | AfraLISP

http://www.afralisp.net/autolisp/tutorials/loading-autolisp-files.php

Home Contact Site Map

AutoLISP Beginners' Tutorials Intermediate Tutorials Advanced Tutorials Application Tutorials Tips'n'Tricks Visual LISP Beginners' Tutorials Intermediate Tutorials DCL Beginners' Tutorials Intermediate Tutorials VBA VBA Tutorials VBA Applications Tips'nTricks AutoCAD Customization Tutorials Tips'n'Tricks Reference AutoLISP Functions Visual LISP Sample Files DXF Group Codes The AutoCAD APIs DCL Tile Attributes AutoLISP DCL Functions System Variables AutoCAD Object Model Download Forum

Loading AutoLISP Files


by Kenny Ramage Note: 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.

1 of 4

10/20/2011 7:11 AM

Loading AutoLISP Files | AfraLISP

http://www.afralisp.net/autolisp/tutorials/loading-autolisp-files.php

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 :
(load "filename")

The.lsp extension is not required.

Menu Loading
The following code samples are one way of loading AutoLisp files from a menu.

Pull Down Menu's :


***POP12 T_Steel [Steel Menu] T_Beams [Drawing Setup]^C^C^P+ (cond ((null C:DDSTEEL) (prompt "Please Wait...")(load "DDSTEEL"))) DDSTEEL

Toolbars :
***TOOLBARS **STEEL TB_DDSTEEL [_Button("Steel", "STEEL.bmp", "STEEL32.bmp")]^C^C^P+ (cond ((null C:ddsteel) (prompt "Please Wait...")(load "ddsteel"))) 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?

Acad.Lsp File.
The Acad.Lsp file is a useful way of loading a library of AutoLisp routines. 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 function :
(load "Lispfile1" "\nLispfile1 not loaded") (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 file.

2 of 4

10/20/2011 7:11 AM

Loading AutoLISP Files | AfraLISP

http://www.afralisp.net/autolisp/tutorials/loading-autolisp-files.php

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.

Command Autoloader
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" Utils2" "Utils3")) (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.

S::Startup Function.
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. For example, 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 () .....Your Definition..... ) (defun C:COPY () .....Your Definition..... ) (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.
Pipe Support Hardware
Manufacturer of Clamps, U Bolts, Turnbuckles, Rods, hangers, & More
www.pipingtech.com

Pipe Support
We are Leading Mfr & ISO Certified Comapny Of Pipe Support.Order Now!
www.technoindustry.in/Call_Us_Now

Setting Out in CAD


Tailor-made lisp programs to help CAD users working on Survey drawing
www.esurveylisps.com

Starlocks
Starlock Push On Fasteners Push On Retainer, Push On Fixes
www.bakfin.com

3 of 4

10/20/2011 7:11 AM

Loading AutoLISP Files | AfraLISP

http://www.afralisp.net/autolisp/tutorials/loading-autolisp-files.php

AutoLISP
AutoLISP Beginners' Tutorials AutoLISP Intermediate Tutorials AutoLISP Advanced Tutorials AutoLISP Application Tutorials AutoLISP Tips'n'Tricks

AfraLISP Archive
Hey, what's happened to AfraLISP? If you've visited our site before, you'll notice some big changes. We're currently revamping the entire site to bring you a better user experience. However, if there's something you can't find, the AfraLISP Archive contains a full copy of the original site.

AutoLISP Learning Resources


Jeffery P Sanders - AutoLISP Tutorials Ron Leigh - AutoLISP Tutorials Pixel Graphics Inc. - AutoLISP Tutorials A'CAD Solutions - AutoLISP Tutorial CAD Digest - AutoLISP Tutorials Autodesk - Customization Tutorials Daily AutoCAD - AutoLISP Tips & Tricks

Online Books
The ABC's of AutoLISP The Visual LISP Developer's Bible

AutoLISP Forums
CADTutor Autodesk Discussion Groups Autodesk User Group International (AUGI) The Swamp 106 Tutorials and reference documents published at AfraLISP so far.
Ads by Google

AutoCAD 2004

Lisp

AutoCAD PDF Free AutoCAD

Back to top Home Cared for by David Watson 2011

4 of 4

10/20/2011 7:11 AM

Potrebbero piacerti anche