Now
I'm going to talk about all the functions of the AutoLISP program. I
already gave you a list of all the functions. Here it is again:
The
Functions
Function Action
START Setting the
limits, erasing everything in the screen, setting the snap and
grid, zooming out of the screen
DRLNS Drawing four lines
FNDET Finding line or
polyline entity
DELPL Delete polyline
DRWPL Draw polyline, no
intersection with other line
DPLIP Draw polyline,
intersection with other line
ENDPR Ending of the
program
The
START And The END Function
Earlier
I talked about those two functions. You know how they work. I don't
have to tell you once more.
The
DRLNS Function
This
function is used to draw the lines in the screen. It is a very simple
function. The LINE command is used twice.
Here
is the function.
(defun-drlns-()
---(command-"line"-(list-120-0)
-------------------(list-10-0)
-------------------(list-10-120)
-------------------(list-120-120)
-------------------""
---)
---(command-"line"-(list-10-60)
-------------------(list-120-60)
-------------------""
---)
)
The
FNDET Function
Let's
first talk about this function. Let me tell you what it does. Let me
tell you what is happening through the function.
There
is asked to make a selection. A selection could have bene made or
there is no selection made. The right mouse button is clicked.
What
ever is done. A selection has been made or no selection has been
made. An entity and the selection point is given back.
If
a selection has been made, then a polyline has been selected or a
line. If a polyline has been selected, then the points of it are
found.
After
the points have been found, the polyline is deleted and the line
under the polyline is found. The points are needed for doing that.
If
a line has been selected, then the entity of the line can easily be
found. And the selection point is known too.
If
no selection has been made, then the entity and the selection point,
that are given back to the main program, get the value of nil.
Here
is the FNDET function.
(defun-fndet-(/-an-el-et-ls-p1-p2-pt-sl-sp-ss-tp)
---(setq-sl-(entsel-"\nSelect-line:
"))
---(if-sl
------(progn
---------(setq-et-(car-sl)
---------------el-(entget-et)
---------------sp-(cadr-sl)
---------------sp-(osnap-sp-"nea")
---------------tp-(cdr-(assoc-0-el))
---------)
---------(setq-ls-nil)
---------(if-(=-tp-"LWPOLYLINE")
------------(progn
---------------(while-(setq-nr-(caar-el))
------------------(if-(=-nr-10)
---------------------(progn
------------------------(setq-pt-(cdar-el))
------------------------(if-ls
---------------------------(setq-ls-(append-
-------------------------------------(list-pt)
-------------------------------------ls
------------------------------------)
---------------------------)
---------------------------(setq-ls-(list-pt))
------------------------)
---------------------)
------------------)
------------------(setq-el-(cddr-el))
---------------)
---------------(setq-p1-(nth-1-ls)
---------------------p2-(nth-0-ls)
---------------------an-(angle-p1-p2)
---------------)
---------------(command-"erase"-et-"")
---------------(setq-ss-(ssget-"c"-(polar-p1-
------------------------------------------an-
------------------------------------------1
-----------------------------------)
-----------------------------------(polar-p2-
------------------------------------------(+-an
---------------------------------------------pi
------------------------------------------)
------------------------------------------1
-----------------------------------)
------------------------)
---------------)
---------------(setq-et-(ssname-ss-0))
------------)
---------)
------)
------(setq-et-nil
------------sp-nil
------)
---)
---(list-et-sp)
)
I
have told you what the function does. And I have told you what is
happening through the function. Lets now see how it done.
Asking
to make a selection. It is done with this line. The ENTSEL function
is used. That function gives back a list.
(setq
sl (entsel "\nSelect-line: "))
This
is an example of the list that is given back by the ENTSEL function.
(<Entity
name: 37d85a0> (61.8922 59.7297 0.000000))
If
a selection has been made, then we want to know the name of the
entity and the selection popint. We use these lines.
(setq-et-(car-sl)
el-(entget-et)
sp-(cadr-sl)
sp-(osnap-sp-"nea")
tp-(cdr-(assoc-0-el))
)
First
we find the name of the entity. It is the first element in the list
from the ENTSEL function. We use the CAR function.
The
second element of the list is the selection point. To find it we use
the CADR function. And we use the OSNAP function.
The
OSNAP function is used to have the point laying on the polyline or
the line that has been selected.
We
also want to know the type of the entity. The type can be LINE or
LWPOLYLINE. A polyline has been selected if it is LWPOLYLINE.
We
find the type of the entity with this line.
(setq-tp-(cdr-(assoc-0-el))
If
a line has been selected, then we have the name of the entity and the
selection point. But a polyline could have been selected.
If
a polyline has been selected, we need to find the points of the
polyline. This is how it is done:
(while
(setq nr (caar el))
(if
(= nr 10)
(progn
(setq
pt (cdar el))
(if
ls
(setq
ls (append (list pt) ls))
(setq
ls (list pt))
)
)
)
(setq
el (cddr el))
)
I
start with a WHILE loop. The WHILE loop continues as long as a number
has been found. The number is in the sub list of the entity list.
The
CAAR function is used. With that function the first sub list of the
entity list is taken and the first element in it.
There
is checked if that number is ten. If so, the point is found in the
sub list with the CDAR function.
Next
the first sub list of the entity list is removed from the entity list
with the CDDR function. And we continue with the WHILE loop.
The
points of the polyline are found in the sub lists that have the
number ten. We create a list. The kist has two points.
After
the points have been found, the polyline is deleted and the line
under the polyline is found. The points are needed for doing that.
The
polyline is deleted with this line:
(command-"erase"-et-"")
These
are the lines that are used to find the line under the polyline. We
use the points of the polkyline for doing that.
Here
are the programming lines:
(setq-ss-(ssget-"c"-(polar-p1-an-1)
(polar-p2-(+-an-pi)-1)
)
)
(setq-et-(ssname-ss-0))
The
angle between the point P1 and P2 is measured. And the points of the
SSGET function are one from the points.
We
do not want to find the lines that cross the line at the points P1
and P2. That is why we go to points 1 from the original points.
We
find a selection set. I call it SS. The first entity in the selection
set is the line that we are looking for. Here is the programming
line.
(setq-et-(ssname-ss-0))
If
a line has been selected, then the entity of the line can easily be
found. And the selection point is known too.
If
no selection has been made, then the entity and the selection point,
that are given back to the main program, get the value of nil.
Very
good. We have found the line and we have found the selection point.
Those two are put in a list and given back to the main program.
We
put these two in a list. This is how it is done:
(list-et-sp)
Next
Post
I
have talked about the FNDET function. You have got a lot of
information. I hope I was clear enough. If not, let me know.
In
my next post I'm going to talk about the DELPL function. That
function is used to delete the polyline that has been drawn.
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.
No comments:
Post a Comment