Loading Programs Automatically 自动加载程序
by http://lee-mac.com/autoloading.html#autoload
Method 1:Using the Startup Suite (加载/卸载应用程序)
快捷键:ap
Method 2: Using the ACADDOC.lsp
Upon opening a drawing or starting a new drawing, AutoCAD will search all listed support paths including the working directory for a file with the filename: ACADDOC.lsp. If one or more such files are found, AutoCAD will proceed to load the first file found.
打开dwg时候,AutoCAD 会搜索支持路径,包括当前的工作目录来查找 “ACADDOC.lsp”,如果有一个或多个被找到,AutoCAD 将加载第一个。
With this knowledge one can edit or create an ACADDOC.lsp to include any AutoLISP expressions to be evaluated upon startup.
因此我们可以编辑或者创造一个 ACADDOC.lsp 来包含任何AutoLISP 语句,使其在程序启动时候被加载。
Things get a little complicated should there exist more than one ACADDOC.lsp file, so, to check if such a file already exists, type or copy the following line to the AutoCAD command line:
(findfile "ACADDOC.lsp")
Should a filepath be returned, in the steps that follow, navigate to this file and amend its contents. Else, if the above line returns nil, you can create your own ACADDOC.lsp in Notepad or the VLIDE and save it in an AutoCAD Support Path.
One clear advantage to using the ACADDOC.lsp to automatically load programs is that, upon migration, it may easily be copied from computer to computer, or indeed reside on a network to load programs on many computers simultaneously.
使用ACADDOC.lsp来自动加载程序的一个明显的优势是程序的可移植性。
The Load Function
(load <filename> [on failure])
If the program file resides in an AutoCAD Support Path, the filename need only be the name of the file to load; else a full filepath is required to locate the file, for example:
如果程序不在支持路径下,应使用全部路径名+文件名。
(load "C:\\MyPrograms\\MyLISP.lsp" "MyLISP Failed to Load.") (load "F:\\My Folder\\MyApp.fas" "MyApp Failed to Load.") (load "MyProgram" "MyProgram Failed to Load.")
One disadvantage of using the load function arises when the user wishes to load a large number of programs. This method will load every program into memory everytime a drawing is opened, hence should a large number of programs require loading, there may be a noticeable increase in the time taken to open a drawing.
The AutoLoad Function
(autoload <filename> <cmdlist>)
This method is best demonstrated with an example. Consider the following LISP program:
(defun c:DrawLine ( / p q ) (if (and (setq p (getpoint "\nSpecify First Point: ")) (setq q (getpoint "\nSpecify Next Point: " p))) (entmake (list (cons 0 "LINE") (cons 10 (trans p 1 0)) (cons 11 (trans q 1 0)))) ) (princ) )
To demand-load this program automatically we could include this line in the ACADDOC.lsp:
demand-load翻译为 直接加载?
(autoload "LineProgram" '("DrawLine"))
Now, upon opening a drawing or creating a new drawing, should the user type DrawLine at the command line, the LineProgram.lsp file will be loaded into the drawing session and the program will start.
Should the program file contain more than one command, additional commands may be added to the list supplied to the AutoLoad function, hence triggering the load of the supplied file upon the user typing any command present in the list.