Professional Documents
Culture Documents
AutoLISP t1
AutoLISP t1
You've tried to decipher some AutoLisp routines but, you are still totally confused!!!
Let's see if we can't help you out.
This tutorial will try and teach you the very basics of AutoLisp programming without overwhelming
you with double-gook.
Let's start up with something very simple and that will give you immediate results. Fire up
AutoCad and type this at the command prompt:
As you noticed using the (alert) function results in a dialogue box being displayed on your screen.
Let's try something else. Type this at the command prompt and press enter :
(setq a (getpoint))
This list, believe it or not, contains the x, y and z coordinates of the point you picked.
x = 496.04
y = 555.06
z = 0.0
(setq a (getpoint))
You could also write the above statement like this to make it more readable :
(dosomething
(dosomethingelse
(andanotherthing)
)
Now you can see why "Lisp" is often known as "Lost in Stupid Parenthesis"
You can also add comments to your coding. Anything preceded with a semicolon is not evaluated
by Autolisp and is treated as a comment, much the same way as the REM statement in Basic is
used. e.g.
(dosomething
(dosomethingelse
The point list should be returned. So, any time that you would like to inspect a variable, just
precede the variable name with "!"
Our getpoint function worked, but it didn't really tell the user what was expected from him by way
of input. Try this now :
Did you notice how Autolisp now asks you for input (and what type of input is expected.)
Press "Enter" again. A line should be drawn between the two points.
The (command) function is used to tell AutoCad what you want it to do.
"Line" Draw a Line
Now this is very nice, but do we have to type in all this coding every time we want to use this
routine?