Saturday, November 9, 2013

AutoLISP For Drawing Donuts 1

Introduction


This time I have got a very special AutoLISP program for you. It is not the typical AutoLISP program that you may expect.


See the picture. At the start of the program a text is drawn and lines are drawn. The program asks to select the text.




Once the text has been selected donuts are drawn at the end of the lines. Have a look at the second picture and see what you get..


The AutoLISP Program


I do not want to waste your time. You want to see the AutoLISP program. Very good. Here is the AutoLISP program.


(defun c:dmp10 (/ ip el ls)
(setvar "cmdecho" 0)
(graphscr)
(start)
(drwng)
(setq ip (seltx))
(setq el (fndln ip))
(setq ls (fndls el ip))
(dwdns ls)
(setvar "cmdecho" 1)
(princ)
)


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


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


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


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


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


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


(c:dmp10)


It is a very long program. The number of lines is 144. But there is nothing that can be done about it. Copy the program and run it.


How The Program Works


You know how I work. First I figure out what the AutoLISP program has got to do. And then I write functions for each performance.


This is what the AutoLISP program has got to do:


1. There are the base settings for limits, snap and grid. And the screen has to be empty. If there is something it has to be deleted.


2. The text and the lines has to be drawn.


3. The text has to be selected.


4. The first line has


5. A list of points has to found.


6. Donus are drawn using the lsit of points.


I have created the following functions for doing that:


1. START
2. DRWNG
3. SELTX
4. FNDLN
5. FNDLS
6. DWDNS


Next Post


Let's talk about all the functions. I will do that in my next post. If you have any questions. Feel free to add a comment to this blog.




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