As
promised in the previous post. This time there is talked about the
functions of the AutoLISP program and why they are there.
What
Needs To Be Done
You
have seen the pictures that tell about what is done with the AutoLISP
program. Let;s mention it to be very clear.
1. The
AutoLISP program starts with an empty screen and snap and grid are
set. There is also zoomed so that the whole screen is displayed.
2. The
two points of the rectangle are entered. The lower left point and
the upper right point are entered.
3. The
rectangle is drawn.
4. The
four corner points of the rectangle are found.
5. The
four corner points are used to draw the donuts in the corner points
of the rectangle.
The
Functions
These
are the functions that do what needs to be done:
1. START
2. Main
Function
3. Main
Function
4. FNDLS
5. DRDNS
6. ENDPR
The
START function sets snap and grid and it also erases everything that
is in the screen. The empty drawing is zoomed.
Picking
the two points of the rectangle and drawing the rectangle could have
been done in a separate function. But that is not done.
The
two points are picked in the main function.
The
points of the rectangle are found with the FNDLS function. The points
are put into a list of points.
The
DRDNS function is used to draw the donuts in the corners of the
rectangle. The list from the previous function is given to the
function.
The
AutoLISP program ends with the ENDPR fucntion.
Talking
About The Functions
The
START Function And The ENDPR Function
Previously
there has been talked about those two functions. No need to talk
about them again. They are supposed to be clear.
The
Main Function
Here
it is:
(defun
c:drdns (/ p1 p2 ls)
(start)
(setq
p1 (getpoint "\nBasepoint: ")
p2
(getcorner p1 "\nUpper point: ")
)
(command
"rectang" p1 p2)
(setq
ls (fndls))
(drdns
ls)
(endpr)
)
In
the main program there is asked to pick the base point of the
rectangle. The GETPOINT function is used for picking the base point.
For
picking the upper point the GETCORNER function is used. The base
point is used as a reference point in that function.
By
using the GETCORNER function a rectangle is drawn in the screen. You
will see what you are getting after picking the two points.
The
FNDLS Function
Here
is the function:
(defun
fndls (/ et el ls ct pl)
(setq
et (entlast)
el
(entget et)
ct
0
)
(while
(setq pl (nth ct el))
(if
(= (car pl) 10)
(progn
(setq
pt (cdr pl))
(if
ls
(setq ls (append (list pt)
ls))
(setq ls (list pt))
)
)
)
(setq
ct (1+ ct))
)
ls
)
Before
talking about finding the points and putting them in a list, I must
tell you something about the rectangle.
The
rectangle is a polyline. And the corner points of a polyline can be
found in the entity list of the polyline.
The
entity list consists of part lists. The corner point is found in the
part list that starts with the number 10.
This
is how the part list of the entity list may look:
(10
39.3750 30.0000 0.000000)
The
FNDLS function finds the entity of the rectangle. It is the last
entity of the drawing. And then the entity list is found.
The
CT variable is set to zero. With a WHILE loop there is walked through
the entity list. The NTH function is used to find a part list.
The
number in the part list is found with the CAR function. Take the part
list from before. The number is 10.
Now
comes the trick. If the number is 10, then a point has to be found.
We want to put the point into a list.
To
find the point the CDR function is used with the part list. The point
in the part list from before is:
(39.3750
30.0000 0.000000)
That
is important. If there is no list, then a list is created with the
point that has been found. That is done with the LIST function.
If
there is a list, then the point is added to the list. It is done
using the APPEND function. See the line with the APPEND function.
The
value of the CT variable is increased with one all the time. This
goes on until no more part list is found. And the WHILE loop stops.
When
the WHILE loop stops a list has been created with all the points of
the rectangle. The list is given back to the main program.
The
DRDNS Function
Here
is the function. It is a very short function. The function only has
seven programming lines.
(defun
drdns (ls / ct)
(setq
ct 0)
(while
(setq pt (nth ct ls))
(command
"donut" 0 2.5 pt "")
(setq
ct (1+ ct))
)
)
The
CT variable is introduced. It gets a value of zero. And then we have
a WHILE loop again. It is used for finding the points.
The
elements of the list are found using the NTH function. As long as a
point is found, the WHILE loop continues.
As
you know. There are only points in the list. A point is found. The
DONUT command is sudeedf to drawe the donut at the point.
Next
the value of the CT variable is increased with one. And the next
point is found. And the next donut is drawn.
All
The Functions
You
have had an explanation of all the functions. Now you have discovered
how AutoLISP deals with a rectangle and donuts.
Something
Completely Different
Here is something
completely different from what you normally read in this blog. It is
an imagination.
Imagine this. One day you
wake up and you are a millionaire! Look at how different your life
will be:
- You
no longer have to worry about your debts, bills, and slaving for
money.
- You
can spend your time doing things you love, spend your time with your
beloved family and friends.
- You
no longer have to worry about money or have to be poor again. Never
again living the life you used to have.
Do you want to be a
millionaire? Make your dream lifestyle came true. Here's your chance
to be a millionaire. Check this out.
Wake Up Millionaire:
http://l1nk.com/rfbzla
To Your Success
Free
AutoLISP Course
Sorry. This offer is only
for my readers from Malaysia. I want to give an AutoLISP course to
them. Free of charge.
I have more than 900
readers. The majority of them is from the USA. More than 500. But I
also have readers from Malaysia. About 120.
I don't know what my
readers from Malaysia are doing. Are they with an engineering firm or
architecture? Or just interested in AutoLISP?
I offer them a free
AutoLISP course. It works like this. You let me know if interested
and I'll come to your place.
I will give the AutoLISP
course at your office. Your people can attend the AutoLISP course.
The course consist of 15 lessons.
The first ten lessons are
about AutoLISP. All the functions of AutoLISP are explained and there
is talked about the system variables.
During the last five
lessons we are going to write an AutoLISP program. The people
attending the course come with a wish.
That is why this offer is
only for my readers from Malaysia. I live in Malaysia. And I do not
see how I could travel abroad.
The AutoLISP course is
completely free. I will not charge you for the course. But I will ask
you to refund my travel expenses.
The people attending the
course will get an e-book about AutoLISP. The e-book is a PDF file.
What is said in the course, can be found in the book.