回望南山
记忆痕迹可以鲜明, 回望往事如数家珍——
posts - 177,  comments - 54,  trackbacks - 0

Before we start with various methods of compiling AutoLISP files, let's have a look at the different file types we'll encounter during this Tutorial :
  • lsp      AutoLISP Program Source file
  • dcl     Contains definitions of AutoCAD Dialog Boxes
  • fas     Compiled AutoLISP Program
  • vlx     Executable Visual Lisp Module
  • prv     Defines the files and options used to build a vlx module

Each time you load AutoLISP source code, the code is translated into instructions the computer understands (executable code). The advantage of having source code translated  

each time you load it is that you can make a change and immediately try it out. This is useful for quickly testing new code, and for debugging that code.
Once you are sure your program is working correctly, translating AutoLISP source code each time it loads is time-consuming. VLisp of AutoCAD provides a compiler that generates executable machine code files from your source files. These executable files are known as FAS files.
Because the executable files contain only machine-readable code, the source code you spent weeks or months developing remains hidden even if you distribute your program to thousands of users. Even strings and symbol names are encrypted by the VLisp of AutoCAD file compiler.

VLisp of AutoCAD also provides features for packaging more complex AutoLISP applications into VLisp of AutoCAD executable (VLX) files. VLX files can include additional resources files, such as VBA, DCL and TXT files, as well as compiled AutoLISP code.

So, let's try and give you a digest of what we've just discussed :

  • If you have a single AutoLISP file, compile it as a fas file.
  • If you have an AutoLISP file with dependencies such as DCL or TXT files, compile it as an Executable Visual Lisp Module vlx file.

Let's start off this Tutorial by compiling a single AutoLISP file.
Copy and paste this into Notepad and save it as "Slot.lsp" :
 

  (defun C:SLOT (/ oldsnap diam lngth pt1 pt2 pt3 pt4 pt5 pt6)
            (setvar "CMDECHO" 0)
            (setvar "BLIPMODE" 0)
            (setq oldsnap (getvar "OSMODE"))
            (setq diam (getdist "\nSlot Diameter : ")
            lngth (getdist "\nSlot Length : "))
            (while
            (setq pt1 (getpoint "\nInsertion point: "))
            (setvar "OSMODE" 0)
            (setq pt2 (polar pt1 0.0 (/ (- lngth diam) 2.0))
            pt3 (polar pt2 (/ pi 2.0) (/ diam 4.0))
            pt4 (polar pt3 pi (- lngth diam))
            pt5 (polar pt4 (* pi 1.5) (/ diam 2.0))
            pt6 (polar pt5 0.0 (- lngth diam)))
            (command "PLINE" pt3 "W" (/ diam 2.0) "" pt4
            "ARC" pt5 "LINE" pt6 "ARC" "CLOSE")
            (setvar "OSMODE" oldsnap)
            );while
            (princ)
            );defun
            (princ)
            
Now fire up AutoCAD and open the Visual Lisp Editor. Type this at the console prompt :

_$ (vlisp-compile 'st "slot.lsp")
T

Have look at the Build Output window :

; (COMPILE-FILES st (D:/drawings/slot.lsp))
[Analyzing file "D:/drawings/slot.lsp"]
..
[COMPILING D:/drawings/slot.lsp]
;;C:SLOT
;
[FASDUMPING object format -> "D:/drawings/slot.fas"]
; Compilation complete.

During compilation, the compiler prints function names and various messages about each stage of compilation. The first stage is syntax and lexical checking of the source code. If the compiler encounters errors, it issues messages and halts the compilation process. The compiler issues warnings if it encounters expressions it considers dangerous, such as redefining existing AutoLISP functions or assigning new values to protected symbols. If the compiler displays warning or error messages, you can view and edit the source code that caused these messages by double-clicking on the message in the Build Output window.

If compilation is successful, as in the example above, the Build Output window displays the name of the compiled output file. This file should be located in the same directory as your AutoLISP source file. Let's have a look at the syntax for (vlisp-compile) :

VLisp of AutoCAD-COMPILE

Compiles AutoLISP source code into a FAS file

(vlisp-compile 'mode filename [out-filename])

NOTE The Visual LISP IDE must be open in order for VLisp of AutoCAD-compile to work.

Arguments :

  • mode

    The compiler mode, which can be one of the following symbols:
    st       Standard build mode
    lsm    Optimize and link indirectly
    lsa     Optimize and link directly

  • filename

    A string identifying the AutoLISP source file. If the source file is in the AutoCAD Support File Search Path, you can omit the path when specifying the file name. If you omit the file extension, .lsp is assumed.

  • out-filename

    A string identifying the compiled output file. If you do not specify an output file, VLisp of AutoCAD-compile names the output with the same name as the input file, but replaces the extension with .fas.
    Note that if you specify an output file name but do not specify a path name for either the input or the output file, VLisp of AutoCAD-compile places the output file in the AutoCAD install directory.

Return Values :

  • T, if compilation is successful, nil otherwise.

Examples

Assuming that slot.lsp resides in a directory that is in the AutoCAD Support File Search Path, the following command compiles this program :

_$ (vlisp-compile 'st "slot.lsp")
T


The output file is named slot.fas and resides in the same directory as the source file.
The following command compiles slot.lsp and names the output file Slot-1.fas :

(vlisp-compile 'st "slot.lsp" "slot-1.fas")

Note that the output file from the previous command resides in the AutoCAD install directory, not the directory where slot.lsp resides. The following command compiles slot.lsp and directs the output file to the c:\my documents directory :

(vlisp-compile 'st "slot.lsp" "c:/my documents/slot-1.fas)

This last example identifies the full path of the file to be compiled :

(vlisp-compile 'st "c:/program files/acad2000/Sample/slot.lsp")

The output file from this command is named slot.fas and resides in the same directory as the input file.


On Page II we'll be having a look at creating compiled AutoLISP files using multiple AutoLISP files and dependency files such as DCL files.

posted on 2008-04-05 16:51 深藏记忆 阅读(787) 评论(0)  编辑  收藏 所属分类: 转载Vlisp

飘过是缘,相识最真

订阅到抓虾
google reader
gougou


点击这里给我发消息


<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(5)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

八面来息

天天充电

同行者

积分与排名

  • 积分 - 59540
  • 排名 - 62

最新评论

阅读排行榜

评论排行榜