Thursday, November 7, 2013

Drawing A Rectangle With AutoLISP 6

Function 8, 9, and 10


Using these functions the dimensions are added to the rectangle, the scale of the drawing is written down, and the AutoLISP program ends.


Function 8


The dimension variables have been set in the seventh function. Now we can add the dimensions to the rectangle.


First the DIMENSION layer is set. And then the dimensions are drawn using the DIMLINEAR command. It is very straight forward.


The dimensions are drawn on a certain distance from the rectangle. We need the scale factor to calculate the distance.


(defun drdim (sc)
(command "layer" "s" "dimensions" "")
(command "dimlinear" p1
(polar p1 0 wd)
(polar p1
(* pi 1.5)
(* 20 sc)
)
)
(command "dimlinear" p2
(polar p2 (* pi 1.5) ht)
(polar p2 0 (* 20 sc))
)
)


Function 9


Now the scale factor needs to be written to the drawing. The TEXT command is used for doing that. It is pretty straight forward.


The TEXT layer is set. And then the position of the text for the scale is calculated. For that the scale factor is used.


That is the trick. With the text command we can only write text. But the scale factor is not a text. It is a real.


So we need to turn the scale factor into a text. That is done using the RTOS function. The number of decimals is set to zero.


(defun drscl (sc)
(command "layer" "s" "text" "")
(command "text" "r"
(setq pt
(polar (list 0 0)
0
(+ (* sc 10)
(* (- 400 10) sc
)
)
)
pt (polar pt
(* pi 0.5)
(* 20 sc)
)
)
(* 10 sc)
0
(strcat "Scale "
(rtos sc 2 0))
)
)


Function 10


Here is the last function of the AutoLISP program. I'm done with the AutoLISP program. Now I must end it.


First I zoom the drawing out. For doing that the ZOOM command is used. Firs the ALL option is used and then the factor 0.8.


At the beginning of the AutoLISP program, the CMDECHO system variable has been set to zero. Now it is set the one again.

(defun endpr ()
(command "zoom" "all")
(command “zoom” “0.8x”)
(setvar "cmdecho" 1)
(princ)
)


The Whole AutoLISP Program


You now have had the whole AutoLISP program. You can copy it to a text file and run it in your CAD program. See how it works.


I have also given you an explanation of the whole AutoLISP program. The program was not spectacular. But you saw some new things.




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