Beowolf logo
 
 
Home    Features    How it works    Tour    Examples    FAQ    Purchase    
 
image
 

Tour transcript

Welcome to the LISP Generator tour. In this tour we will look at how the LISP Generator works, the LISP Generator menus, a couple of sample programs, and the resulting LISP code.

How it works
Using the LISP Generator is surprisingly easy. The LISP Generator runs inside AutoCAD and provides a menu interface that you use to describe, in general terms, the programs that you want to create. When necessary, the Generator will ask you a question or two about the details of what you are requesting. For instance, if you indicate that you want your program to open an external data file, the Generator will need to ask you for the name of the file. From this sort of straight-forward input, LISP Generator writes the entire program for you. You don’t need to know, or learn, any LISP at all to use the Generator, and there is not limit to how large or complex your programs can be.

The Menus
The LISP Generator is completely menu-driven, though all of the menu items can also be run from the AutoCAD command line. The FILE menu is used to Begin and End the process of a Generating a program and the CONFIGURE and HELP menus are self-explanatory. The HOT-WORDS menu contains a set of universal commands that can be used in any situation and at any prompt. Some of the Hot-Words are transparent commands that simply report data about your work in progress. Others provide a very powerful method by which you have the option to nest commands within larger commands, which may in turn be nested within even larger commands, and so on.

For the most part however, you actually design your program using the LISP Generator’s ‘Tools’ menu. Each tool acts as a sort of logical building block. For instance there is a tool called 'Extract' that you would select whenever you need your program to extract data from an object in the drawing; another tool called 'Get' that you would use to have your program prompt its user for input (such as supplying a number, picking a point, or selecting an object); another called 'File' that you would use to write/read data to/from an external file; and so on. Each tool might give rise to several lines of LISP code, but as far as you're concerned it's just a single item. There are 15 such tools and through them you have access to nearly the entire AutoLISP language. The tools that you use and the order in which you use them will determine the design of your program. With most of the tools, the LISP Generator will ask you a couple questions (usually multiple-choice) about the details of what you have requested. From this, the Generator literally writes your entire program for you.

Example1
As we mentioned earlier, there is no limit to how large or complex your programs can be, but for now we're going to keep things simple. This utility program is called CHGLYR. It prompts its user to select a single object, then a group of objects. The program then automatically changes the layer of the objects in the group to match that of the first object. In this program, we'll be using the GET tool, the EXTRACT tool, and the RECORD tool.

We start the program by selecting BEGIN from the FILE menu and naming the program. Rather the CHGLYR, let's use CL for short.

First, we need our program to prompt its user to select the single entity. The GET tool is employed anytime we need our program to GET any sort of input from its user. So lets use the GET tool, and from the sub menu we'll choose "entity". The Generator then asks us to name the variable in which the user's response will be stored. We can give the variable any name we choose. Let’s name it ENTITY1. This variable can then be used later on in the program to reference the stored data, in this case, whatever entity the user might select. Lastly the GET tool gives us the option to write out how we would like the prompt to appear in the program. Let have read "Extract layer from what object:".

Now that we have the input from the user, let's extract the layer name from ENTITY1. We do this by selecting the EXTRACT tool and when the Generator asks from which entity we will be extracting data, we enter ENTITY1. The Generator then brings up a table of all of the data associated with this entity and we select LAYERNAME from the table. As with the GET tool, the Generator then asks us to name a variable in which the LAYERNAME can be stored. Let call it LN1.

The last tool we will use is the RECORD tool. Record is used whenever you need your program to include AutoCAD commands. It works very much like a macro recorder. In fact, it can be used completely by itself for just that purpose. The recording process is controlled by commands such as PAUSE, SSPAUSE, and STOP. As with macro recorders, Pausing causes a temporary break in the recording which, when played back, leaves a kind of blank spot that the user can change. You'll see how it works shortly.

Here we will be using the RECORD tool to incorporate AutoCAD's CHANGE command into our program. After selecting the RECORD tool we are informed by the Generator that the recorder is now "on" and we are returned to the command prompt. So to include the CHANGE command, we simply run it as we normally would. This is where the fact that the LISP Generator runs inside AutoCAD really pays off. Not only are we able to use AutoCAD commands in their familiar environment but the commands are actually executed as we go. This makes it very easy to see what's going on and to follow along with the process while generating a program. After entering the CHANGE command, we are prompted by AutoCAD to select objects. Because we want the user to be able to choose whatever objects he wants when he runs our program, we will use a PAUSE here, specifically a Selection-Set PAUSE, rather than recording ourselves selecting specific objects. Next we record our answer the familiar change command prompts for "PROPERTIES" then "LAyer". AutoCAD then prompts us for the new layer name. We stored this earlier in the variable LN. We have two options here, either type in !LN as we would can in normal AutoCAD operation or use the Generator's VAR hot-word. This hot-word indicates to the Generator that you are about to supply a variable name in response to a prompt. Without it AutoCAD would think that the new layer was named "LN" rather than the name stored by the variable LN. That takes care of the CHANGE command and the RECORD tool, so we select STOP to end the recording.

That also takes care of the program, so we select DONE from the FILE menu.

Example2
Now that you have seen in detail how the Generator works lets take a look at another program. In this example, we won't bother discussing minor details that don't affect the overall design of the program such as the names of the variables or the file. These sorts of things are entirely up to you anyway. This program will read an external data file and automatically insert blocks based on the data in the file. Lets say that the file is from a spreadsheet and each row, or line of data, contains values for x, y, z, and two attributes. To accomplish this task we will be using the FILE, LOOP, OPERATIONS, and RECORD tools.

To start, we select BEGIN from the file menu and give the program a name. The first tool we use is FILE. From the submenu, we select OPEN A FILE and then give the name of the data file. Because there are going to be lots of data lines in the file, we will cause the main section of the program to repeat using the LOOP tool. This tool is very powerful and has options for automatically setting up all sorts of loops including ten different step-through loops. Step-through loops will repeat once for each item in a group of items essentially stepping through the group one item at a time no matter how many items there are. Setting up these complex loops is as easy as selecting them from the submenu. As you can see there are options for stepping through the items in a list, the objects in an AutoCAD selection set, the vertices of a polyline, the attributes of a block, and so on. The one we select is STEP THROUGH THE / LINES IN A DATA FILE. The Generator will ask "what file?" and we supply the file we just opened. The Generator then automatically reads a single line from the data file for us to use. We are now inside the loop. Everything we do inside the loop now will, when the program runs later, be repeated once for every line in the data file. In other words, we only need to insert one block using one line of data in order to have the program insert a block for every line of data.

So, now we need to read the individual values from the data line which is still a single string of data. We accomplish this using the OPERATIONS tool. It's a well organized library of simple operations grouped by the data type the operation works with. First, we use this tool to convert it to a list by selecting OPER / CONVERTIONS / DATA STRING TO LIST. Then we use it to read each value from the list and store it in a variable by selecting OPER / LISTS / NTH ITEM IN LIST. Lastly, we need to combine the values for x, y and z into a point using OPER / POINTS / BUILD A POINT.

We are now ready to insert the block. As with the first example, we will use the RECORD tool to record ourselves using AutoCAD's INSERT command. When AutoCAD prompts for the insertion point, rather than selecting a point with the cursor we type in VAR and supply the point variable we just created. We then default through the scale and rotation prompts until asked for the attribute values where we again use VAR and supply the attribute values we just read. Once the block is inserted, we use STOP to end the recording process.

That's pretty much it except for a couple loose ends, the open loop and the open data file. The LISP Generator would automatically close both of these for us if we forgot, but let's go ahead and close them ourselves. First, we select the LOOP tool then CLOSE to end the repetitive part of the program. Next, we use the FILE tool and select CLOSE from the submenu to close the file we opened at the beginning of the program. Lastly we select DONE from the FILE menu and save the program to a file.

The Resulting Programs
Now lets have a look at the resulting program. As you can see our three LISP Generator tools have given rise to quite a bit of LISP code. Our new program has built-in error checking and internalized variables to avoid conflicts with other programs. The program is well formatted and organized with indentation indicating depth of nesting. The program is full of commented notes in English that describe in detail what is going on in each section of code. Lastly, this program is standard AutoLISP and can be run on any AutoCAD machine with or without the LISP Generator.

   ©1989-2008