Saturday, November 9, 2013

AutoLISP For Drawing Donuts 2

The First Four Functions


In my previous post I told you about all the functions that I have for the AutoLISP program. I told you what each function is doing.


Now I'm going to give you an explanation of the first four functions. Read it and understand how the functions work.


The START Function


Here is the START function:


(defun start (/ ss)
(command "limits" (list 0.0 0.0)
(list 120.0 120.0)
)
(command "zoom" "all")
(command "zoom" "0.8x")
(command "snap" "on")
(command "snap" 10)
(command "grid" 10)
(setq ss (ssget "c" (list 0 0)
(list 120 120)
)
)
(if ss
(command "erase" "all" "")
)
)


It is a pretty short function. The number of lines is only 17. And the function is not very complicated.


The limits of the drawing are set. Next there is zoomed to the limits of the drawing using the ZOOM All command.


Then SNAP and GRID are set. Although. We don't really need them. But hey. It looks good, doesn't it?


And now we can see if any thing has been drawn in the area of the drawing. The SSGET fucntion is used. Is anything found?


If anything is found, then the ERASE command is used. Everything is erased from the drawing. And we have an empty screen.


The DRWNG Function


Here is the DRWNG function.


(defun drwng ()
(command "text" (list 0 30)
10
0
"ROOM"
)
(command "line" (list 100 0)
(list 100 100)
""
)
(command "line" (list 80 100)
(list 110 100)
""
)
(command "line" (list 80 100)
(list 80 120)
""
)
)


It is a very simple function. I don't ned to explain the function. A text is drawn and three lines are drawn.


The SELTX Function


Here is the SELTX function.


(defun seltx (/ et et el ip)
(setq et (entsel "\nSelect the text: ")
et (car et)
el (entget et)
ip (cdr (assoc 10 el))
)
ip
)


There is asked to select the text. The text is selected using the ENTSEL function. But take care. The selection point is also given back.


The selection point is the second element of the list that is given back. We want the entity. And that is the first element.


So we use the CAR function to get the first element of the list. Next we find the entity list and the insertion point.


The insertion point is given back by the function to the main program. It is used in the main program.


The FNDLN Function


Here is the FNDLN function.


(defun fndln (ip / ct ds el et ss tp)
(setq ct T
ds 10
)
(while ct
(setq ss (ssget "c" ip (polar ip 0 ds)))
(if (= (sslength ss) 2)
(setq ct nil)
)
(setq ds (+ ds 10))
)
(setq et (ssname ss 0)
el (entget et)
tp (cdr (assoc 0 el))
)
(if (not (= tp "LINE"))
(setq et (ssname ss 1)
el (entget et)
)
)
el
)


It is easy to find the line. We want the lowest vertical line. That line is at the right of the text. So it is easy to find.


We use the SSGET function. We go for the crossing option. Two points are needed. The insertion point and a calculated point.


The calculated point is 10 to the right of the insertion point. A selection set is found. The length of the selection set is found.


There is always the text in the selection set. So the length is always one. If the line is found, then the length is two.


There is a WHILE loop in the function. The CT variable is set to true. As long it is true, the loop continues.


If the length of the selection set is two, then the value of the CT variable is set to false. And the loop terminates.


Now we have a selection set with two entities. But we want the entity that is the line. We check the type of the first entity.


If the type is not line, then we take the second entity. The entity list of the second entity is given back to the main program.


Two More Functions


There are two more functions. I'm going to talk about them in my next post. I will give an explanation of them.




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