Thursday, December 19, 2013

11 AutoLISP Functions For Quickly Drawing Views 2

The AutoLISP Program


Here is the AutoLISP program. You will see the eleven functions here.


(defun c:crtvw (/ ls p1 p2 ls lt ht tp)
(start)
(clscr)
(drwor)
(zmdrw)
(setq ls (fdpts)
p1 (nth 0 ls)
p2 (nth 1 ls)
)
(setq ls (fltht p1 p2)
lt (nth 0 ls)
ht (nth 1 ls)
)
(setq tp (seltp))
(if (= tp "Flat")
(drwfl p2 lt ht)
(drwsh p2 lt ht)
)
(zmdrw)
(endpr)
)


(defun start (/ ss)
(setvar "cmdecho" 0)
(command "limits" (list 0 0)
(list 280 120)
)
(command "snap" 10)
(command "zoom" "extents")
(command "zoom" "0.8x")
(setq ss (ssget "c" (list 0 0)
(list 280 120)
)
)
(if ss
(command "erase" "all" "")
)
(command "-style" ""
"Courier New"
0
1
0
"No"
"No"
)
(command "zoom" "all")
(command "zoom" "0.8x")
)


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


(defun drwor (/ p1 p2)
(setq p1 (getpoint "\nFirst point rectangle: ")
p2 (getcorner p1 "\nOpposite point
rectangle:
"
)
)
(command "rectang" p1 p2)
(command "explode" (entlast))
)


(defun zmdrw ()
(command "zoom" "extents")
(command "zoom" "0.8x")
)


(defun fdpts (/ d1 d2 d3 d4 e1 e2 el p1 p2 p3 p4 ss)
(setq p1 (getvar "vsmin")
p2 (getvar "vsmax")
)
(setq ss (ssget "c" p1 p2)
e1 (ssname ss 0)
el (entget e1)
p1 (cdr (assoc 10 el))
p2 (cdr (assoc 11 el))
d1 (distance (list 0 0) p1)
d2 (distance (list 0 0) p2)
)
(if (< d1 d2)
(setq p1 p1)
(setq p1 p2)
)
(setq e2 (ssname ss 1)
el (entget e2)
p3 (cdr (assoc 10 el))
p4 (cdr (assoc 11 el))
d3 (distance (list 0 0) p3)
d4 (distance (list 0 0) p4)
)
(if (> d3 d4)
(setq p2 p3)
(setq p2 p4)


(list p1 p2)
)


(defun fltht (p1 p2 / x1 x2 lt y1 y2 ht)
(setq x1 (car p1)
x2 (car p2)
lt (abs (- x1 x2))
)
(setq y1 (cadr p1)
y2 (cadr p2)
ht (abs (- y1 y2))
)
(list lt ht)
)


(defun seltp (/ tp)
(initget 1 "Flat Shaft")
(setq tp (getkword "\nType: Flat/Shaft: "))
)


(defun drwfl (pt lt ht / dt pt wd)
(setq wd (getint "\nWidth: ")
dt (getint "\nDepth: ")
)
(command "line" (setq pt (polar pt 0 10))
(setq pt (polar pt 0 wd))
(setq pt (polar pt
(* pi 1.5)
ht
)
)
(setq pt (polar pt pi wd))
"c"
)
(command "line" (setq pt (polar pt
(* pi 0.5)
(+ 10 ht)
)
pt (polar pt pi 10)
)
(setq pt (polar pt
(* pi 0.5)
dt
)
)
(setq pt (polar pt pi lt))
(setq pt (polar pt
(* pi 1.5)
dt
)
)
"c"
)
)


(defun drwsh (pt lt ht / pt)
(setq pt (polar pt 0 (+ 10 (* ht 0.5)))
pt (polar pt (* pi 1.5) (* ht 0.5))
)
(command "circle" pt (* ht 0.5))
(command "line" (setq pt (polar pt
pi
(+ 10
(* ht 0.5)
)
)
pt (polar pt
(* pi 0.5)
(+ 10
(* ht 0.5)
)
)
)
(setq pt (polar pt
(* pi 0.5)
ht
)
)
(setq pt (polar pt pi lt))
(setq pt (polar pt
(* pi 1.5)
ht
)
)
"c"
)
)


(defun endpr ()
(setvar "cmdecho" 1)
(princ)
)


(c:crtvw)


Next Post


Here you have the AutoLISP program. Copy it to a text file and save it under the name CRTVW.LSP. Load it into AutoCAD and work with it.


In the next post I'm going to talk about all the functions. I'm going to explain how they work and why they are there.


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