Saturday, June 14, 2014

Parametric Drawing


We can create AutoCAD drawings using AutoLISP. Here is an AutoLISP program that does the job. The name of the program is NEWDR.LSP.


The AutoLISP Program


(defun c:newdr (/ p1 p2 p3 p4 p5 p6 p7 sd ts ws)
(setvar “cmdecho” 0)
(setq p1 (getpoint “\nPosition door: “)
sd (getdist “\nStructural dimension: “)
ws (getdist “\nWidth style: “)
ts (getdist “\nThickness style: “)
p2 (polar p1 0 ts)
p3 (polar p2 (/ pi 2) ws)
p4 (polar p3 pi ts)
p5 (polar p2 0 sd)
p6 (polar p3 0 sd)
p7 (polar p3 (/ pi 2) sd)
)
(command “pline” p1 “w” 0 0 p2 p3 p4 “c”)
(command “copy” “l” “” p1 p5 “”)
(command “pline” p2 p5 “”)
(command “copy” “l” “” p2 p3 “”)
(command “pline” p3 p7 “”)
(command “arc” p6 “c” p3 p7)
(command “zoom” “a”)
(command “zoom” “0.8x”)
(setvar “cmdecho” 1) (princ)
)
(c:newdr)


Using the program a door will be drawn. See how the door looks. As you can see. The door has different sizes and a position.



Copy The AutoLISP Program


That is so good about the listing of an AutoLISP program. You can save it on your hard disk and use it again. Copy the program to a text file.


That is important. When the listing of an AutoLISP program is saved, it is saved with the extension LSP. It can be loaded into your CAD program.


Loading The AutoLISP Program


Let's talk about how to load an AutoLISP program into the AutoCAD program. That must be done first before you can use the AutoLISP program.


I will talk about loading the AutoLISP program into IntelliCAD. Loading it into AutoCAD is done in the same way. So don't worry.


You are in IntelliCAD. Click on Tools in the menu. In the pop-up menu click on Load Application. The Load Application files dialog box is displayed.


In the dialog box click on the Add File button. You can go to different folders and you can select the AutoLISP file that you want to load.


Click on the file. And click on the Open button. You come back into the Load Application file dialog box. Click in the Load button.


The AutoLISP file is now loaded into IntelliCAD. And you can start it by typing its name at the prompt.


Starting Automatically


Before I talk about the AutoLISP program, I want to say something about what has been added to the program. At the end you see:


(c:newdr)


Through that line the AutoLISP starts as it has been loaded into IntelliCAD. As you can see. The name of the AutoLISP program is in the line.


Functions


In the AutoLISP program we find functions. The first function we find it the DEFUN function. Here is the syntax of the DEFUN function:


(defun <symbol> <argument list> <expression> ...)


This how the DEFUN function is used for defining an AutoLISP function. SYMBOL is the name of the new AutoLISP function.


Arguments


In the argument list you find all the arguments that the new AutoLISP function needs to run properly. If not there, then an error occurs.


Local Variables


In the argument list you can find a slash. After the slash comes a list of variables. Those variables are local variables.


The local variables only have a value in the function. Outside the function they have no value. Or the value of them is nil.


If no argument list is given then the symbol of an empty list must be used. This is how that symbol looks like: ().


Variables that are not defined as local have a value outside the function. They have a value when the function is no longer running.


Here are some examples:


(defun funct (x y) – the function has two arguments


(defun funct (/ a b) – the function has two local variables


(defun funct (z / a) – the function has no argument and one local variable


(defun funct () - the function has no arguments



In the AutoLISP function the GETPOINT and GETDIST functions are used. To get information. In a separate chapter we talk about the functions.


As you can see. AutoCAD commands were used in the AutoLISP program. I will talk about using AutoCAD commands in another report.


Exercise


You now have seen how an AutoLISP program is created. You have seen how distances can be entered and how AutoCAD commands are used.



Go ahead. Write your own program. This time the program is going to draw a house. Enter the sizes of the house.

No comments:

Post a Comment