Sunday, November 17, 2013

AutoLISP And Lines Around A Text In AutoLISP

Introduction


The AutoLISP program, that I have got, is not too complicated. You select a text, you enter a space, and lines are drawn around the text.


The AutoLISP Program


Here is the AutoLISP program. A text is selected, the spacing between the text and the liens are entered, and the lines are drawn.


(defun c:txtbx (/ ls et sp ls lg ip ht al)
(setvar "cmdecho" 0)
(setq ls (sssel)
et (nth 0 ls)
sp (nth 1 ls)
)
(setq ls (fndsz et)
lg (nth 0 ls)
ip (nth 1 ls)
ht (nth 2 ls)
al (nth 3 ls)
)
(drlns sp lg ip ht al)
(setvar "cmdecho" 1)
(princ)
)


(defun sssel (/ et sp)
(setq et (car (entsel "\nSelect text: "))
sp (getint "\nSpace around text: ")
)
(list et sp)
)


(defun fndsz (et / el ls p1 p2 lg ip ht al)
(setq el (entget et)
ls (textbox el)
)
(setq p1 (nth 0 ls)
p2 (nth 1 ls)
lg (- (car p2) (car p1))
ip (cdr (assoc 10 el))
ht (cdr (assoc 40 el))
al (cdr (assoc 72 el))
)
(list lg ip ht al)
)


(defun drlns (sp lg ip ht al)
(if (= al 4)
(setq ip (polar ip (* pi 0.5) (* ht 0.5)))
)
(setq ip (polar ip pi sp)
ip (polar ip (* pi 1.5) sp)
)
(command "line" ip
(setq ip (polar ip
0
(+ lg (* sp 2))
)
)
(setq ip (polar ip
(* pi 0.5)
(+ ht (* sp 2))
)
)
(polar ip pi (+ lg (* sp 2)))
"c"
)
)


(c:txtbx)


Three Functions


The TXTBX AutoLISP program works with three functions:


1. SSSEL
2. FNDSZ
3. DRLNS


The first function is for selecting a text and for entering the spacing between the text and the lines.


In the second function the sizes of the text are found. This is what is found:


- The length of the text
- The insertion point of the text
- The height of then text
- The alignment of the text


In the third function the lines are drawn around the text. There is a consideration for the spacing that has been entered.


The Alignment Of The Text


I must explain something about the alignment of the text. A text can have the following alignments:


- Left
- Center
- Middle
- Right
- Bottom left
- Bottom Center
- Bottom Right
- Middle left
- Middle Center
- Middle Right
- Bottom left
- Bottom Center
- Bottom Right


The alignment of the text can be found in the entry list of the text. It has the number 72. But it is no really important.


In the entity list the insertion point of the text is found. It is at the bottom left of the text. Except when the alignment is middle.


If the alignment of the text is middle then the insertion point is below the bottom left of the text. It is half the height lower.


You can see that the alignment of the text is middle. If is found in the entity list. There you find (72 . 4).


Look at the DRLNS function. In it is checked what the alignment of the text is. If it is 4, then the insertion point is adjusted.


How The AutoLISP Program Works


I think that is very clear. I do not have to explain how it works. Or let me talk about the TEXTBOX function.


You find the TEXTBOX function in the FNDSZ function. The entity list of the function is given to the function and a list is given back.


In the list are two points of the text. These points are the lower left point and the upper top point.


You can use the points to find the length of the text. That is done by using the CAR function on the points.


How It Looks


Here is how it looks after the AutoLISP program runs and the text has been selected. Lines are drawn around the text.




The text has been selected and for the spacing 2 is entered. See how it looks. But you can copy the file and see for yourself.




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


No comments:

Post a Comment