The Visual LISP Integrated Development Environment1 Nov, 2001 By: Bill Kramer
The following is an excerpt from my new book, The AutoCADet's Guide to Visual LISP (CMP Books, www.cmpbooks.com), modified to fit the magazine-column format. The second chapter of the book, which introduces the Visual LISP development environment, is the source of this article. I hope you find it to be a useful jump into the VLIDE and consider purchasing the entire book to read the remaining topics not covered here.
The "Visual" in Visual LISP comes from the development environment. Before Visual LISP and the IDE (Integrated Development Environment), AutoLISP developers were forced to use text editors or word processors that know nothing about LISP syntax and requirements. Testing involved loading the files into AutoCAD to see if they worked. Debug tools were left to the invention of the programmers. Eventually, independent developers created tools to improve that situation and one of them evolved into what we now know of as Visual LISP. The Visual Development Environment is a set of tools that exist in a window that is separate from AutoCAD's main window. In this window, there are multiple child windows to help you manage source files and projects as well as test programs.
This column explores the various windows in the VLIDE. Since this is the tool we will be using to create new programs, it is important that we know the basics of how to use it from the onset. There is a lot of depth in the tool--meaning it will take you some time before you become comfortable with all that it has to offer. The purpose of this column is to expose you to the concepts and methods involved. We will start by looking at the various windows and terms found in the environment this month. Next month, we will look into the basic operations involved in developing programs. Those include creating new files, editing existing files, testing the programs, and hunting down syntax problems in the code.
There is no way a single column can handle all the features found in the VLIDE. The intent of this article and the subsequent ones is to introduce the concepts and provide a foundation for using the tool. By the end of the series, you should be able to start the VLIDE, load a program file into the editor, perform basic syntax checks, and test the program--watching the symbols change as it runs.
Figure 1. VLIDE windows can be intimidating for first-time users who are not familiar with their functions.
What's an IDE?
Let's start by getting some of the terminology down. If you have been around computers for a while, you may have noticed the emergence of terms such as IDE and Visual for many programming languages. An IDE (Integrated Development Environment) is a group of windows in which you load, run, test, and debug programs to create applications. They are often considered visual in nature compared to the older ways of developing programs using a text editor; the windows make use of colors and icons to let the programmer quickly navigate from one task to another in the creation of an application. Just like most tools, the more you work with an IDE, the better you will be at using it for your purposes.
In essence, an IDE is a cool text editor as well as a debugging environment created to make programming easier. In an IDE, the programmers--you and I--are the users. That means all the tools are meant to help the programmer become more productive. At first you may encounter some items that will cause you to wonder about their usefulness. Be assured that you will use most of them at some time in your programming career if you get deeply involved in software development. On the other hand, if you only program every so often, you may never find the need to call on some of these tools. The key element to keep in mind is that they are provided with programmers in mind. That means they are potentially useful to help you get the job done--at least that was the intent.
The IDE supplied with Visual LISP is a major step forward from using a basic text editor for the entering and editing of Visual LISP programs. A variety of tools are provided in the IDE just for the LISP developer to make our work a lot easier. Some of the tools found in the Visual LISP IDE include parentheses matching, automatic indentation (for pretty printing), color coding of source text, dialog-box preview, function-search utility, and tracking of symbols. Later on, we are going to take a look at the IDE and cover some of the areas where you will use it the most. As you begin to use the IDE, be sure to reference the online help files since you will find many other tools and shortcuts designed specifically for you, the Visual LISP programmer.
The key concept to understand is that the VLIDE combines the tools into a single environment. You will only use a couple of these tools at a time, so don't feel overwhelmed, no matter how intimidating this all may appear at first. And it will appear intimidating, as you can see in the VLIDE windows shown in Figure 1 and their respective functions listed in Table 1.
As you can see from the figure and table, there is more to the IDE than you might have originally imagined. Keep in mind that these tools are for you, the programmer. The goal is to make you more productive in programming applications and macros for AutoCAD. But you will need to spend time with them in order to achieve a decent level of efficiency. As we explore Visual LISP, you'll see how these tools can be employed to your advantage. So let's get started with the basics of running the IDE.
Figure 2. When starting Visual LISP for the first time, only an empty screen with a console and a tracing window will appear. This confuses most first-time users since they expect to see some prompts or guidance on their next step.
Starting the Visual LISP IDE inside AutoCAD 2000 (or higher) is simply done with a command in AutoCAD. There are several options available and, as a programmer, I tend to use the command-entry method most often. Type VLISP or VLIDE at the AutoCAD command line; either of these commands will do.
You can also start the IDE via menu selections in AutoCAD. Click on the Tools menu and then select the AutoLISP option where you will find the entry "Visual LISP Editor."
When the IDE starts, the last project loaded will be displayed as if you have just walked away from it a few minutes ago. As you create applications, this feature will be helpful. You don't have to reload the project and associated files to start working on the code. It is loaded and ready to go. For most of you, this entry into the IDE will be your first so no project will be under way.
If you are starting Visual LISP for the first time, an empty screen will be presented containing just the console and trace windows, as shown in Figure 2. This confuses a lot of people as they expect to see some sort of starting screen telling them what to do next. But this is a programmer's tool set, and as such, it cannot anticipate what you are about to do with it-even though the most common thing to do is to load an existing LSP file or start a new one. We will return to loading a file and starting a new one in a minute, but first let's finish looking at the initial impression of Visual LISP.
If the Visual LISP IDE does not load, then there is something wrong with your installation of AutoCAD. Visual LISP is installed as part of the standard installation of AutoCAD 2000 (and later). You may need to install the program again, selecting the standard options in order to enable Visual LISP. Note that you need to have the full version of AutoCAD 2000; Visual LISP is not available for the AutoCAD LT versions and only an initial version is included in AutoCAD Release 14.
There are multiple windows and icons visible when you first start the software. There is also a pulldown menu full of even more commands and options. This is where many people stop cold since they are not sure what to do next. Their first impression must be that there is not much to the VLIDE. The console window does not seem to do much and the trace window just tells them what version of the VLIDE they have loaded. But I stress again that the VLIDE is a power tool and not something for the casual user. It is for programmers to use when they create applications. And I will add that an AutoCAD programmer is anyone who is customizing the system to make it more productive. You don't have to use the VLIDE every day to be considered an AutoCAD programmer.
Now let's briefly examine how to switch from the VLIDE to and from AutoCAD itself. When writing LISP programs for AutoCAD, it is not uncommon to have to return to the AutoCAD drawing editor to review command sequences, test a program that involves interactive graphics, or just load a drawing at someone's request.
LSP and DCL File Editor Windows Color text-editor windows with knowledge about LISP and DCL formats, keywords, and structures. This is where you will spend most of the time in the VLIDE entering and editing program text. These windows will appear when you create a new text file or load one. Console Window This window loads and runs program files and functions from the "$" prompt. Programs behave much in the same way they would if run from the AutoCAD command line. The console window will never go away in the VLIDE. You can minimize it to get it out of the way. Trace Stack Window This window shows basic contents of the stack while the evaluator is running, and is used when debugging a program. The stack is where the calling sequence of a program is stored during execution. Error Trace Window This window shows error related information, such as the expression that failed. Use it in conjunction with the trace stack window for getting your programs to work properly. Symbol Service Window This window shows current binding (value) of symbols. This dialog box is used to set the flags for various symbols when debugging an application. You must close it before using any other windows in the VLIDE. Watch Window This window shows binding of symbols and other information while the program is running. When you set a break point, the watch window helps you see what the symbol being watched contains. Apropos Window This window finds matching keywords for internal symbols given a few characters. With more than 800 internal functions, this search utility is very helpful, even for experts. Project Window This window lists the various files included in a project. Double-click on an entry in the list box to display the associated file in a text editor window. This window can be placed outside of the main VLIDE window in order to get out of the way of the code windows. Trace Window This window traces the activity of the Visual LISP environment. Only referenced when something serious goes wrong in the system. Like the console window, this window does not go away in the VLIDE; most of the time you will minimize it.
To completely exit the VLIDE, select either the window exit icon (X in upper-right corner) or the File menu option "Exit." Selecting either of these exit options will normally close the current project, giving you the opportunity to save any files you may have modified. Control of the computer is then returned to the AutoCAD drawing editor. VLIDE is finished running, but Visual LISP is still available from the AutoCAD command line to run your functions and expressions. Normally you exit the VLIDE when you are done programming for a while.
You can return to AutoCAD and leave the VLIDE running. This is the normal way to use the VLIDE with AutoCAD. You can jump into AutoCAD and accomplish something then return to the VLIDE to continue programming. There are two basic methods for accomplishing that task. The "Activate AutoCAD" command is available in the form of an icon as well as a menu selection in the Window grouping. You can also return to AutoCAD by selecting the application from the Windows task bar (normally at the bottom of the screen).
Note that a taskbar entry containing "Visual LISP for AutoCAD" will also appear. When started inside AutoCAD, the VLIDE becomes another Window application that is running. You can switch between the AutoCAD drawing window and Visual LISP at any time. Select AutoCAD or Visual LISP on the Windows taskbar (normally at the bottom of your Windows desktop) to change from one to the other. When you start the Visual LISP IDE, you should see the normal Windows cursor. It will be an arrow or text-editing symbol. Should you happen to see an unusual icon, as the one shown in Figure 3, it is an indication that Visual LISP is busy and the IDE is not available for text editing. The busy cursor will appear when you are running a Visual LISP function. To get back to the normal Windows cursor, return to AutoCAD and cancel or finish the running Visual LISP expression.
That's all the space we have for this month. Next time, we'll dig into the icons and operations a little more and learn about how the VLIDE can help us debug applications. I strongly encourage you to try out the VLIDE if you are using another text editor to write Visual LISP code. With a little practice, you will find it to be a very powerful weapon in your arsenal. Until next time, keep on programmin!
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor and Autodesk Technical Evangelist Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD video tips. Subscribe to the free Cadalyst Video Picks newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!
Poll not yet available.