Chapter 19: Visual Lisp After completing this Chapter, you will be able to do the following: • What is AutoLISP • Launching Visual LISP • Terminology and Fundamental Concepts What is AutoLISP? AutoLISP is based on the LISP programming language, which is simple to learn and very powerful. AutoCAD has a built-in LISP interpreter that lets you enter AutoLISP code on the command line or to load AutoLISP code from external files. AutoLISP applications are stored in ASCII text files with the .lsp extension. These files generally have a header portion that describes a routine, itsuse, and any specific instructions. This header might also include comments that document the author and the legal information regarding the use of the routine. You can view and edit these files with a text editor or word processor that can produce an ASCII text file. Invoke the APPLOAD command or the AutoLISP load function to load an application. Loading an AutoLISP application loads the AutoLISP code from the LSP file into system's memory. By default, the acad.lsp loads only once, when AutoCAD starts, while acaddoc.lsp loads with each individual drawing. This lets you associate the loading of the acad.lsp file with application startup, and the acaddoc.lsp file with drawing startup. The acad.lsp and acaddoc.lsp startup files are not provided with AutoCAD. It is up to the user to create and maintain these files. AutoLISP has been enhanced with Visual LISP (VLISP), which offers an integrated development environment (IDE) that includes a compiler, debugger, and other development tools to increase productivity. VLISP represents the next generation of LISP for AutoCAD. It adds more capabilities and extends the language to interact with objects using ActiveX. Visual LISP provides three file format options for AutoLISP applications : Reading ASCII AutoLISP file (.lsp) - is an ASCII text file that contains AutoLISP program code. Reading an FAS file (.fas) - is a binary, compiled version of a single LSP program file. Reading a VLX file (.vlx) - is a compiled set of one or more LSP and/or DCL files. Launching Visual LISP VLISP operates within AutoCAD Tools menu Choose AutoLISP > Visual LISP Editor On-screen prompt vlisp (ENTER) Launching Visual LISP Visual LISP initial window The Visual LISP window is displayed as a separate window with two basic child windows: VLISP console Trace (by default it’s minimized) The main areas within the VLISP window are: Console window - allows you to enter VLISP commands and is scrollable. You can test VLISP expressions as well as review previous commands or operations in this window. Status bar - current conditions related to the operations are displayed in the bottom left bar of the VLISP window. Menu bar - menu bar operates like the conventional Windows menu bar with a brief description of the selected menu item displayed in the status bar. Trace window - This window is minimized during startup. It contains information regarding the VLISP release number and other startup messages. You will also use this window during debug operations. Toolbars - Toolbars allow you to issue commands using the pointand-click method. Instead of navigating the menu bar or memorizing the command syntax to be entered in the console window you can select a button to activate the command. There are five principal toolbar groups: Standard, Tools, Search, Debug, and View. Terminology and Fundamental concepts Lists, operators and arguments, types, parentheses, the exclamation point, and the concept of the function list comprise the basis of AutoLISP. Lists - Practically everything in AutoLISP is a list of one sort or another. Functions are usually represented as a list of expressions enclosed in parentheses. Operators and Arguments - Arguments are those items in a function list on which the operator operates. Types - Arguments are classified by their type. Parentheses - The primary mechanisms for entering and leaving AutoLISP and entering expressions within AutoLISP are the open and close parentheses. Exclamation Point - A leading exclamation point in response to a prompt is another mechanism for entering AutoLISP. This tells AutoCAD that the symbol following the exclamation point is an AutoLISP variable that has been set equal to some value and that AutoCAD should use the value of the variable as a response to the prompt.