[go: up one dir, main page]

0% found this document useful (0 votes)
34 views4 pages

Alert "Hello and Welcome To Autolisp!"

This document provides an introduction to basic AutoLisp programming. It demonstrates how to use common AutoLisp functions like (alert) and (getpoint) to display messages and get input from the user. It explains the use of variables to store point coordinates retrieved from (getpoint). The document also shows how to write a simple AutoLisp program to draw a line between two user-selected points using (command) and variables to specify the start and end points. Comments are introduced as a way of adding explanatory notes in code.

Uploaded by

David Resende
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views4 pages

Alert "Hello and Welcome To Autolisp!"

This document provides an introduction to basic AutoLisp programming. It demonstrates how to use common AutoLisp functions like (alert) and (getpoint) to display messages and get input from the user. It explains the use of variables to store point coordinates retrieved from (getpoint). The document also shows how to write a simple AutoLisp program to draw a line between two user-selected points using (command) and variables to specify the start and end points. Comments are introduced as a way of adding explanatory notes in code.

Uploaded by

David Resende
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

So, you've never programmed in AutoLisp before!

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:

(alert "Hello and welcome to AutoLISP!")

Now press enter. This should appear on your screen :

Well Done, you've just used AutoLisp to make AutoCAD do something.

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))

Then choose a point anywhere on the screen.

A "list" of numbers, looking something like this, should appear in your command window.

(496.0 555.06 0.0)

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

The AutoLisp coding :

(setq a (getpoint))

Means, in plain English :

Get a point from the user and store the x, y and z

values as a list in variable "a".

Did you notice how everything is enclosed within parenthesis?

All AutoLisp functions are surrounded by parenthesis.

As well, AutoLisp allows you to "nest" your functions.

This lets you write a function that evaluates another function.

Just remember, that you must leave the nest with an equal number of parenthesis. Here's an

example :

(dosomething (dosomethingelse (andanotherthing)))

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

(andanotherthing) ;This is a comment


) ;This is another comment
) ;and another comment
The statement we wrote earlier, told AutoLisp to get a point from the user and store the value in

variable "a".

Now type this at the command line :

!a

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 :

(setq a ( getpoint "\nChoose a Point : "))

Did you notice how Autolisp now asks you for input (and what type of input is expected.)

Let's write a programme.

Type in each of these lines, one at a time, pressing "Enter" at the end of each line, then choosing a

point.

(setq a (getpoint "\nEnter First Point : "))

Press "Enter" then select a point.

(setq b (getpoint "\nEnter Second Point : "))

Again, Press "Enter" then select a second point.


(command "Line" a b "")

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

a From the point stored in variable "a"

b To the point stored in variable "b"

"" Enter to close the Line command.

Now this is very nice, but do we have to type in all this coding every time we want to use this routine?

You might also like