Friday, December 20, 2013

AutoLISP Functions For Quickly Drawing Views 3

As promised in the last post. This timeis talked about the functions of the AutoLISP program. Explained is how they work.


Functions


The AutoLISP program has got the following functions:


- CRTVW
- START
- CLSCR
- DRWOR
- ZMDRW
- FDPTS
- FLTHT
- SELTP
- DRWFL
- DRWSH
- ENDPR


CRTVW


This is the main function of the AutoLISP program. Through this function calls are made to the separate functions of the program.


Here is the function:


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


You can see what calls to functions are made.


START And ENDPR


There has been talked about those two functions. So there is no need to repeat what has been said. Here are both functions:


(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 endpr ()
(setvar "cmdecho" 1)
(princ)
)

CLSCR


When the program starts, there is made sure that the screen is empty. Everything that is in the screen is erased.


It is done with the CLRSR function. Here it is:


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


The ZOOM command is used and of it the EXTENTS option is used. That way everything that is in the screen is displayed.


The lower right point of the screen and the upper left point of the screen is found. Those points are used with the SSGET function.


If a selection set is found with the SSGET function, then the selection set is erased totally.


DRWOR


The first rectangle is drawn by the user. It is done with this function. Here is the function:


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


The user enters two points. First the user enters the lower right point of the rectangle and then the upper right point of the rectangle.


Using the RECTANGLE command the rectangle is drawn. Next the rectangle is exploded with the EXPLODE command.


The rectangle is exploded, because we need separate lines for what comes next.


ZMDRW


We want the rectangle displayed in the screen. That is where the ZMDRW function comes in. Here is the function.


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


The ZOOM command is used and the EXTENTS option of that command. Next the display of the screen is scaled down with factor 0.8.


FDPTS


The lower left point of the rectangle and the upper right point of the rectangle are needed. Later you will see why.


Here is the FDPTS function for finding the two points:


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


The drawing has been zoomed out and it has been scaled down with the ZMDRW function. The two points of the screen are found.


The points are used with the SSGET command to get the selection set. The selection set is the rectangle. Do you now see why it was exploded?


There are four entities in the selection set. The fist entity is the horizontal line and the second entity is the vertical line.


The points of both lines are taken to find the lower left corner of the rectangle and the upper right corner of the rectangle.


The start point and end point of each line is taken. And then the distance to the zero point is measured.


The smallest distance gives the lower left point of the rectangle. The biggest distance gives the upper right corner of the rectangle.


The two points that have been found are put in a list and given back to the main function.


FLTHT


The length and the height of the rectangle are needed for the rest of the program. It is found with this function.


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


The two points that were found with the previous function are given to the function. The X values are found with the CAR function.


The CADR function is used to find the Y values of the points. When the X values and Y values are found the length and the height can be found.


The length and the height are put in a list and given back to the main function.


Next Post


In this post not all functions have been specified. Some functions are remaining. You will find them in the next post.


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