Sunday, November 10, 2013

AutoLISP For Drawing Donuts 3

The Two Remaining Functions


Here is an explanation of the two remaining functions. Here is an explanation of the FNDLS function and the DWDNS function.


The FNDLS Function


Here is the FNDLS function.


(defun fndls (el ip / e1 e2 el et ls p1 p2 pt ss)
(setq et (cdr (car el))
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
)
(setq ls (list p1)
ls (append (list p2) ls)
)
(setq ss (ssget "c" p1 p1))
(if (= (sslength ss) 1)
(setq ss (ssget "c" p2 p2))
)
(setq e1 (ssname ss 0)
e2 (ssname ss 1)
)
(if (equal e1 et)
(setq et e2)
(setq et e1)
)
(setq el (entget et)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
)
(setq ls (append (list p1) ls)
ls (append (list p2) ls)
)
(setq ss (ssget "c" p1 p1))
(if (= (sslength ss) 1)
(setq ss (ssget "c" p1 p2))
)
(setq e1 (ssname ss 0)
e2 (ssname ss 1)
)

(if (= e1 et)
(setq et e1)
(setq et e2)
)
(setq el (entget et)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
)
(setq ss (ssget "c" p1 p1))
(if (= (sslength ss) 1)
(setq pt p1)
(setq pt p2)
)
(setq ls (append (list pt) ls))
ls
)


This function is a very long function. It has 50 lines. And the function works on the three lines of the drawing.


Handling The First Line


Let me start with looking at the first line of the drawing. These are the lines of the function that handle the first line.


(setq et (cdr (car el))
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
)
(setq ls (list p1)
ls (append (list p2) ls)
)


The entity list of the first line is given to the function. The entity list is used to find the name of the line entity.


It is the first element of the entity list. We use the CAR function to find it. But we want the second element. The CDR function is used.


Using the entity list we find the two points of the list. And we store them in the LS variable. We create a list out of them.


That is important. We use the LIST function to create a list from the point. We want to add the second point to the list.


For adding the second point to the list the APPEND function is used. But it only works if a list is added to the list.


So we can only add the second point to the list if the point has been turned into a list. Therefor we use the LIST function again.


Handling The Second Line


These are the lines of the FNDLS function that deal with the second line.


(setq ss (ssget "c" p1 p1))
(if (= (sslength ss) 1)
(setq ss (ssget "c" p2 p2))
)
(setq e1 (ssname ss 0)
e2 (ssname ss 1)
)
(if (equal e1 et)
(setq et e2)
(setq et e1)
)
(setq el (entget et)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
)
(setq ls (append (list p1) ls)
ls (append (list p2) ls)
)


We have found the two points of the first line. The second line is going through one of the two points.


We create a selection set at the first point of the first line. We see how many entities are in that selection set.


If the number is one, then we need to take the selection set, that is found at the second point. We have a selection set with two entities.


We find the entities in the elections set. We check that it is not the first line. And we take the points of the proper line.


The two points are added to the list. We have done it before. You know how it is done. The points are turned into a list.


Handling The Third Line


We go to the lines of the function that deal with the third line of the drawing. Here they are:


(setq ss (ssget "c" p1 p1))
(if (= (sslength ss) 1)
(setq ss (ssget "c" p1 p2))
)
(setq e1 (ssname ss 0)
e2 (ssname ss 1)
)
(if (= e1 et)
(setq et e1)
(setq et e2)
)
(setq el (entget et)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
)
(setq ss (ssget "c" p1 p1))
(if (= (sslength ss) 1)
(setq pt p1)
(setq pt p2)
)
(setq ls (append (list pt) ls))


It is pretty much the same as what was done with the lines for handling the second line of the drawing.


There is the point found that produces a selection set with two entities. There is checked that the third line is taken.


The remaining point is found. At that point there is a selection set with only one entity. The point is written to the list.


The list is given back to the main program. We need the list for adding all the donuts at the points of the line.


The DWDNS Function


Here is the DWDNS function.


(defun dwdns (ls / ct pt)
(setq ct 0)
(while (setq pt (nth ct ls))
(command "donut" 0 2.5 pt "")
(setq ct (1+ ct))
)
)


We start with the introduction of the CT variable. That variable gets the value zero. It is used for the NTH function.


We want to find all the points that are stored in the LS variable. Once we have a point the DONUT command is used.


The function works with a WHILE loop. The WHILE loop continues as long as a point is found. And a donut can be drawn.


That Is All


You now have seen how the AutoLISP works. You have got the compete AutoLISP program and you have got an explanation.


What I said. Was it clear? If not. Let me know. Add a comment to this blog. And I will come back to you. I'll give you an answer.




Telling Others


Do you like what you have read? Do you know other people, that could be interested? Could you tell them about this blog?




Comment


In the mean time. If you have any questions. Or you want to tell me something. Feel free to add a comment to this blog.


I would love to hear from you. And when you come to me with a comment. I will give a reply to your question or remark.




Warning


Don't spend a lot of money on AutoCAD Light. It is only for creating 2D drawings and it doesn't support AutoLISP.


There is a very similar CAD program. And that is completely free. The name of the program? DraftSight.


How to get it? Do a search on Google for “download DraftSight”. And you will find where you can download the program.






Only Create Drawings


When your CAD operators don't create the borders of your drawings, a lot of time is saved. You get your drawings much faster.


I have created a program that does exactly that. An AutoCAD drawing has been created and the program draws a border around it.


If you want to see how the program works, go to YouTube. You'll find the working of the program here:


http://www.youtu.be/O8Zy6n9zS8Q


Now the AutoLISP program gives you the choice to select the size of your border. You can select A4, A3, A2, or A1.


Maybe you already know the size of the border of your drawing. Maybe all your drawings have the size A1. If so. Let me know.


That is important. The program finds the proper scale of your drawing. Or do you already know what the scale always is?


I can write the AutoLISP program that you want. The price? I will only charge you RM 600.-. That is less than US $ 200.-.






You are welcome to publish my article provided you include the resource box with links intact.




Resource Box


Jos van Doorn is an AutoLISP programmer and blogger. He is originally from Holland and now he lives in Malaysia.



He is the founder of the Make AutoCAD Fast business. Make AutoCAD Fast is writing AutoLISP programs for AutoCAD users.



Make AutoCAD Fast created an AutoLISP program for drawing a border around AutoCAD drawings. The program can be found on YouTube.
http://www.youtu.be/O8Zy6n9zS8Q



Jos is writing a blog. In it are AutoLISP programs with information and it is about Make AutoCAD Fast. You can find his blog here:


http://www.makeautocadfast.blogspot.com


Maybe you have a question. Or want to tell me something. You can contact me on this e-mail address:


makeautocadfast@ymail.com


This article may be freely reprinted or distributed in its entirety in any Ezine, newsletter, blog, or website. As long as the following resource box is added:


-------------------------------------------------
This article is written by Jos van Doorn. He is an AutoLISP programmer who has helped engineering firms and architects to get their AutoCAD drawings fast, without waiting for hours.


You can find more valuable information about his
business and AutoLISP at his blog. It is here:


http://www.makeautocadfast.blogspot.com


If you want to contact him. Go to his blog and leave a comment.
-------------------------------------------------


No comments:

Post a Comment