Be sure to read the Introduction below this table before proceeding with these lessons.
|LESSON TITLE||SAMPLE PROGRAMS|
|1 - Sample program||mslot (draw milled slot)|
|2 - Syntax, arithmetic, & nesting||area3 (calculate area of triangle, 3 sides known)|
|3 - Variables, setq, & formulas||ba (calculate bend allowance)|
|4 - Editors, file format, & defun||presston (calculate press tonnage)|
|5 - User input & system variables||table (draw blank table)|
|6 - Geometry & command functions|| squangle (draw square at any angle)
boltcirc (draws a circular pattern of holes)
balloon (draw numbered leader balloon)
|7 - Trig functions|| rightss (solve right triangle, side-side known)
rightsa (solve right triangle, side-angle known)
bctable (create table of bolt circle dimensions)
|8 - Conditionals & getkword|| solids (calculate volume & surface area)
rf (display reference file)
|9 - Iteration|| ccircles (draw concentric circles)
curvtext (draw text on a circular baseline)
monthly (calculate monthly mortgage payments)
|10 - Strings & printing|| sysvars (display values in key system variables)
strfacts (string facts, analyze a sentence)
stext (spaced text, user sets vertical spacing)
|11 - List manipulation|| ol (on-line, locate point on an imaginary line)
trimlist (identifies points near a central point)
|12 - Files|| write (writes any number of lines to a file)
read (reads file, displays or adds to drawing)
balloon2 (cf. balloon, saves balloon dia. in file)
|13 - Entity access|| c-scale (scales several circles in one operation)
cove (adds a cove, or reverse fillet, to two lines)
polycnc (polyline's CNC information sent to file)
|14 - Table access|| balloon3 (cf. balloon2, saves more info. in file)
tstyles (lists text styles by variable/fixed height)
|15 - Miscellaneous||ba2 (cf. ba, adds default prompts & error routine)|
Viewing the lessons
It is best to view these lessons with your browser window maximized. This is especially true when you are looking at the illustrative code and the sample programs that are contained in each lesson.
There is a rather standard way of presenting AutoLISP programs that involves indenting nested functions. This format helps the programmer and anyone else viewing the program to instantly "see" the structure of each section of the program, which is very helpful in understanding how the program works. If your browser window is too narrow, you may not see the program the way it was intended to appear.
Elements in the lessons
These lessons are progressive; they build from the easiest topics to the more difficult ones. The first lesson is merely a sample program with lots of documentation to explain how it works. Each subsequent lesson includes the following three elements in various proportions:
Trying a program -- preferred method
If you don't want to type the programs, you can use a typical Windows capture method to save them, following these steps:
After you have made a copy of the program using one of the above methods, and placed it in an .LSP file, you must load the program into AutoCAD. In AutoCAD, enter
Include the opening and closing parentheses and the quotation marks. (Regarding the double back-slashes: you can, if you prefer, replace each pair of double back-slashes with a single forward-slash.) In place of folder use the name of the folder on which you saved the program. In place of programname use the name of the file in which you saved the program. (You don't need to add the .LSP extension because the load function looks for .LSP files by default).
It is also possible to place the file in a folder that is in the AutoCAD library path. (Here is one easy way to find out what AutoCAD's library path is: In AutoCAD, use the INSERT command and, when prompted for a block name, enter a name you know does not exist, either in the drawing or on file. The error message that appears on screen will list all the folders in the library path.) When you place the file in a folder in the library path, you can use the load function without including a path, as follows: (load "programname")
If the program loads successfully, the command line should report the name of the program that has been loaded from file. If you receive an error message, check to make sure that the file exists where you thought it did, and that there are no mistakes in the content of the file.
Then run the program by entering its name. (The program name follows the "defun", but does not include the "c:")
Be sure to experiment. Don't
just run the program once. Run it several times with different input
each time. Then revise the program, save it, reload it, and run it
several more times. The more you work with AutoLISP programs, the
more you will understand them.