Sunday, October 13, 2013

AutoLISP Program For Drawing A Cabinet 11




The Complete Program


(defun c:cabin (/ pt ls wd nr oh th)
(setvar "cmdecho" 0)
(clscr)
(setq pt (list 0 0)
ls (getsz)
wd (nth 0 ls)
nr (nth 1 ls)
oh (nth 2 ls)
th (nth 3 ls)
)
(drcab pt wd nr)
(drtop pt wd nr oh th)
(drdrw pt wd nr)
(drhnd pt wd nr)
(setdm)
(drdim pt wd nr oh th)
(command "zoom" "extents")
(command "zoom" "0.8x")
(setvar "cmdecho" 1)
(princ)
)


(defun clscr (/ ss)
(command "zoom" "extents")
(setq p1 (getvar "vsmin")
p2 (getvar "vsmax")
)
(setq ss (ssget "c" p1 p2))
(if ss
(command "erase" "all" "")
)
)


(defun getsz (/ di fl hi ls nr oh th wd wi)
(setq fl 0
wd 600
oh 50
th 25
)
(while (= fl 0)
(setq di (load_dialog "c:/make/cabin.dcl"))
(new_dialog "cabin" di)
(setq wi (dimx_tile "im")
hi (dimy_tile "im")
)
(start_image "im")
(fill_image 0 0 wi hi 0)
(slide_image -100 -100
(+ wi 100)
(+ hi 100)
"c:/make/cabin.sld"
)
(end_image)
(set_tile "wd" (itoa wd))
(set_tile "nr" "2")
(set_tile "oh" (itoa oh))
(set_tile "th" (itoa th))
(mode_tile "wd" 3)
(start_list "nr" 3)
(add_list "3")
(add_list "4")
(add_list "5")
(add_list "6")
(end_list)
(action_tile "accept" "(setq ls (value))
(done_dialog)")
(start_dialog)
(unload_dialog di)
(setq fl (nth 0 ls)
wd (nth 1 ls)
nr (nth 2 ls)
oh (nth 3 ls)
th (nth 4 ls)
)
)
(list wd nr oh th)
)


(defun value (/ fl nr oh th wd)
(setq wd (atoi (get_tile "wd"))
nr (atoi (get_tile "nr"))
oh (atoi (get_tile "oh"))
th (atoi (get_tile "th"))
)
(cond
((= nr 0)
(setq nr 3)
)
((= nr 1)
(setq nr 4)
)
((= nr 2)
(setq nr 5)
)
((= nr 3)
(setq nr 6)
)
)
(if (< wd 400)
(progn
(alert "Minimum width is 400")
(setq fl 0)
)
(setq fl 1)
)
(list fl wd nr oh th)
)


(defun drcab (pt wd nr)
(if (tblsearch "layer" "cabinet")
(command "layer" "s"
"cabinet"
""
)
(progn
(command "layer" "m"
"cabinet"
"c"
"green"
""
""
)
)
)
(command "line" pt
(setq pt (polar pt 0 wd))
(setq pt (polar pt
(* pi 0.5)
(+ (* nr
(+ 100
25
)
)
25
)
)
)
(setq pt (polar pt pi wd))
"c"
)
)


(defun drtop (pt wd nr oh th)
(command "line" (setq pt (polar pt
(* pi 0.5)
(+ (* nr
(+ 100 25)
)
25
)
)
)
(setq pt (polar pt pi oh))
(setq pt (polar pt (* pi 0.5)
th
)
)
(setq pt (polar pt
0
(+ wd
(* oh 2)
)
)
)
(setq pt (polar pt
(* pi 1.5)
th
)
)
(polar pt pi oh)
""
)
)


(defun drdrw (pt wd nr)
(repeat nr
(command "line" (setq pt (polar pt 0 25)
pt (polar pt
(* pi 0.5)
25
)
)
(setq pt (polar pt
0
(- wd 50)
)
)
(setq pt (polar pt
(* pi 0.5)
100)
)
(setq pt (polar pt
pi
(- wd 50)
)
)
"c"
(setq pt (polar pt pi 25))
)
)
)


(defun drhnd (pt wd nr / e1 e2)
(setq pt (polar pt 0 175)
pt (polar pt (* pi 0.5) 65)
)
(repeat nr
(command "line" pt
(polar pt 0 (- wd 350))
""
)
(setq e1 (entlast))
(setq pt (polar pt (* pi 0.5) 20))
(command "line" pt
(polar pt 0 (- wd 350))
""
)
(setq e2 (entlast))
(drarc e1 e2)
(setq pt (polar pt (* pi 0.5) 105))
)
)


(defun drarc (e1 e2 / el p1 p2 p3 p4)
(command "fillet" e1 e2)
(setq el (entget e1)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
el (entget e2)
p3 (cdr (assoc 10 el))
p4 (cdr (assoc 11 el))
)
(command "erase" e1 e2 "")
(command "line" p2 p1 "")
(setq e1 (entlast))
(command "line" p4 p3 "")
(setq e2 (entlast))
(command "fillet" e1 e2)
)


(defun setdm ()
(command "-style"
"dimension"
"courier new"
0
1
0
"no"
"no"
)
(if (tblsearch "layer" "dimension")
(command "layer" "s"
"dimension"
""
)
(progn
(command "layer" "m"
"dimension"
"c"
"red"
""
""
)
)
)
(setvar "dimasz" 10)
(setvar "dimcen" 10)
(setvar "dimclrt" 2)
(setvar "dimdec" 0)
(setvar "dimdli" 5)
(setvar "dimexe" 5)
(setvar "dimexo" 5)
(setvar "dimgap" 5)
(setvar "dimtad" 1)
(setvar "dimtdec" 0)
(setvar "dimtih" 0)
(setvar "dimtoh" 0)
(setvar "dimtvp" 5)
(setvar "dimtxsty" "dimension")
(setvar "dimtxt" 10)
)


(defun drdim (pt wd nr oh th)
(command "dimlinear" pt
(setq pt (polar pt 0 wd))
(polar pt (* pi 1.5) 35)
)
(command "dimlinear" pt
(setq pt (polar pt
(* pi 0.5)
(+ (* nr
125
)
25
)
)
pt (polar pt 0 oh)
)
(polar pt 0 35)
)
(command "dimlinear" pt
(polar pt (* pi 0.5) th)
(polar pt 0 35)
)
(setq pt (list 0 0))
(command "dimlinear" (setq pt (polar pt
(* pi 0.5)
(+ (* nr
125
)
25
)
)
)
(polar pt pi oh)
(polar pt (* pi 1.5) 35)
)
)




(c:cabin)


13 Posts Now


This post is very long. Still. There is a lot more that I want to say. I want to say something about:


1. Programming in AutoLISP
2. This AutoLISP Program


I will do it in two separate posts. Sorry. In the beginning I was saying that this series only has 11 posts. That is now 13 posts.


Next Post


In the next post I'm going to talk about programing in AutoLISP.




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:


Make AutoCAD Fast
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


No comments:

Post a Comment