Parametric Design With AutoLISP
Print This Post
![]() |
Author | Prof. Günay Özmen |
| Profession | Istanbul Technical University | |
| Construction M.Sc. Dep. | ||
| AutoLISP Specialist | ||
AutoLISP programming language is one of the ways to increase the effectiveness of AutoCAD applications. This article is intended for those who have not yet had an introduction to AutoLISP. We will introduce the AutoLISP language and explain some simple applications of it. It is obvious that for experienced AutoLISP users, this articles will not be of any contribution.
1. Introduction.
One of the most common aplications used for increasing efficiency in AutoCAD is the use of blocks. Usually, commonly used parts are defined as blocks an then used throughout the drawing. However, general purpose blocks can be defined as independent drawings and used in any other drawing. Logs containing block characteristics that can be accessed with the ATTEXT command are one of the most useful ways of forming Data Bases in drawings. As the uses of the ATTEXT command can be a seperate article, it will be out of this context.
2. Advantages and Disadvantages of Blocks.
As is known, you can enter different scale factors in X, Y, Z directions when inserting blocks. This way, it is possible to use blocks that include two parameters in the plane or three parameters in the space. Let’s have a rectangular block as in Fig.1

Fig.1 Rectangular Block.
This block can be considered as a sheet of metal, concrete column, table, cupboard or maybe even a bed depending on the kind of drawing it is used in. Both dimensions can be defined as a single unit length while making the block and when applying it, A and B can be set as X and Y scales, thereby making use of parametric design. These types of parametric design applications can only be applied for 2 dimensions on a plane (3 in space). Blocks cannot be used as elements of parametric designs when more than 2 parameters are applied as seen in Fig.2 and Fig.3

Fig.2 Several parameters Fig.3 Similar parameters.
Very commonly in engineering and architectural drawings, we repeatedly need to draw objects with numerous parameters but similar composition. Fig.4

Fig.4.Examples of parametric design.
“Parametric Design” refers to these kinds of drawings. Programs that make up DXF and/or SCR logs, AutoLISP or ADS programs are used in parametric design.
Programs that write DXF or SCR logs can be written with any programming language (FORTRAN, BASIC, C++ etc.). These take drawing parameters as inputs and produce the DXF/SCR logs after necessary geometrical calculations, which will be used by AutoCAD. The programs and the details of the ADS language are left out in this article. In the following lines, the properties of the AutoLISP language will be introduced and explained using a simple example.
3. AutoLISP Programming Language.
Among the commonest methods to simplify the use of AutoCAD applications is the AutoLISP programming language LISP is a “List Processing” language that is a basic tool in artificial intelligence. AutoLISP is a version o the LISP language developed by Autodesk to be used in AutoCAD applications. With AutoLISP, “parametric design” is possible through the use of various parameters, whereas systematic/global editing, printing, constructing drawings is easily possible. In practice, it has been seen that with the use of simple LISP programs, AutoCAD efficiency is considerably increased.
In AutoLISP programs, data is the drawing parameters. Later, using geometrical functions related to the object being drawn, points called “basic points” are marked out. These are the points that the AutoCAD commands will use. The programs are completed with functions including the required AutoCAD commands. The interesting thing about AutoLISP programs is that they require little AutoLISP knowledge. Indeed, for many parametric design programs, knowing the elemantary functions such as polar, distance, angle is enough. The use of more complicated functions such as entity and selection-set is not necessary. Naturally, the usage of if, cond, while, repeat and other functions and sub-programs, enhance effectiveness. Nevertheless, the use of only the elemantary functions are enough for most parametric design programmings.
A comprehensive list f AutoCAD commands can be found in the ‘Help’ file or the ‘AutoCAD Reference Manual’ conserned. There are also many foreign and local prints about both AutoLISP and VisiualLISP, some published by Autodesk. As this is just an introductory article, the details are not included in this context.
4. Example: Drawing a bracket (SAMPLE.LSP)
As a simple example, a program drawing a symmetrical bracket in Fig.3 will be looked into. The drawing parameters are the lengths A, B and left corner point. The program list is as shown (List.1):
; A sample lisp program that draws a bracket
(defun c:brc()
(setq A (getreal “\n A:”))
(setq B (getreal “\n B:”))
(setq C (- A B))
(setq P1 (getpoint “\nDefine lower left corner:”));Calculate points
(setq P2 (polar P1 0 A))
(setq P3 (polar P2 (/ pi 2) B))
(setq P4 (polar P3 pi C))
(setq P5 (polar P4 (/ pi 2) C))
(setq P6 (polar P5 pi B));Draw bracket
(command “_pline” P1 P2 P3 P4 P5 P6 “c”)
List.1: SAMPLE.LSP
At the head of the list, values for A and B, and ‘lower left corner’ points are entered and then a helping value C (A-B) is computed. Later, ‘basic points’ (Fig.5) are marked out using the (polar) function.

Şekil.5 Temel noktalar
The (polar) function, provided a point P1,marks out a second point using a line of lenght ‘L’, making an angle of ‘a’ (in degrees radian) from the horizontal. The general form of this function is;
(polar P1 a L)
In the program above, 0, pi/2 or pi is to be used as ‘a’, and A, B, or C, as ‘L’. In the last line of the program, the ‘line’ command in AutoCAD was used to finish the drawing.
AutoLISP programs need to be coded in ASCII (you can use Notepad) and the file extension saved as LSP. The program is loaded using Tools/Load Application.. command in AutoCAD. To run the program, you can simply enter the ‘brc’ as a command.
(command …) function can be made to do a lot of AutoCAD operations. For example, to hatch the drawn object, below the ‘dwg’ part;
(setq LGTH (/ (distance P1 P4) 2))
(setq P7 (polar P1 (/ pi 4)LGTH ))
(command “bhatch” “P” “ANSI31″ “” “” P7 “”)
commands can be added. P7 here, is the midpoint of the line joining P1 and P4. It should be noted that when programming in AutoLISP only the command line can be used as dialog boxes cannot be used. The FILEDIA system variable should be turned OFF especially during the test periods of the program. (editor’ note: by putting ‘-‘ in front of the commands while entering them in the command prompt, you can easily prevent the dialog boxes from appearing).
As a different application, after marking out the basic points, the ‘solid’ command can be used instead of ‘line’.
(command “solid” P2 P3 P1 P4 P6 P5 “”)
Regards
Similar Posts
Rate this article:


(3 votes, average: 4.67 out of 5)