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.
|