AutoCAD 2012 帮助
 
load
 
 
 

Evaluates the AutoLISP expressions in a file

(load filename [onfailure]) 

The load function can be used from within another AutoLISP function, or even recursively (in the file being loaded).

Arguments

filename

A string that represents the file name. If the filename argument does not specify a file extension, load adds an extension to the name when searching for a file to load. The function will try several extensions, if necessary, in the following order:

  • .vlx
  • .fas
  • .lsp

As soon as load finds a match, it stops searching and loads the file.

The filename can include a directory prefix, as in “c:/function/test1”. A forward slash (/) or two backslashes (\\) are valid directory delimiters. If you don't include a directory prefix in the filename string, load searches the AutoCAD library path for the specified file. If the file is found anywhere on this path, load then loads the file.

onfailure

A value returned if load fails.

If the onfailure argument is a valid AutoLISP function, it is evaluated. In most cases, the onfailure argument should be a string or an atom. This allows an AutoLISP application calling load to take alternative action upon failure.

Return Values

Unspecified, if successful. If load fails, it returns the value of onfailure; if onfailure is not defined, failure results in an error message.

Examples

For the following examples, assume that file /fred/test1.lsp contains the expressions

(defun MY-FUNC1 (x) 
          ...function body...
) 
(defun MY-FUNC2 (x) 
          ...function body...

and that no file named test2 with a .lsp, .fas, or .vlx extension exists:

Command: (load "/fred/test1")

MY-FUNC2

Command: (load "\\fred\\test1")

MY-FUNC2

Command: (load "/fred/test1" "bad")

MY-FUNC2

Command: (load "test2" "bad")

"bad"

Command: (load "test2") causes an AutoLISP error

See Also

L Functions
lambda
last
layoutlist
layerstate-addlayers
layerstate-compare
layerstate-delete
layerstate-export
layerstate-getlastrestored
layerstate-getlayers
layerstate-getnames
layerstate-has
layerstate-import
layerstate-importfromdb
layerstate-removelayers
layerstate-rename
layerstate-restore
layerstate-save
length
list
listp
load
load_dialog
log
logand
logior
lsh