Saturday, December 21, 2013

AutoLISP And DCL 1

Introduction


You know about DCL. Your AutoLISP program can work with dialog boxes. And you need a DCL file for doing that.


In the DCL file the dialog box is specified. What is specified, is displayed as the AutoLISP file starts.


But we have a problem. As long as the dialog box is displayed, we don't have access to AutoLISP. Or AutoCAD.


Well. Here is an AutoLISP program that works with a dialog box and that goes around this problem. You have access to AutoLISP.


How The Program Works


As the program starts a dialog box is displayed. Here is the dialog box that is displayed.




We can select a text by clicking on the button with the label “Select text”. If we do that the dialog box disappears.


In the command area of AutoCAD the following text is displayed:


Select text:


Now you can select a text.


After selecting a text the dialog box is displayed again. Now the user can select the spacing that he or she wants.


The spacing is the distance between the text and the box that will be drawn around the text. It can be from two till five.


But. You know how AutoCAD users can be. The dialog box invites us to select a text. But we have AutoCAD users that don't select a text.


They click on the OK button without selecting a text. So we need to warn them. That is done with this dialog box.




The user clicks on the OK button in the warning dialog box and the original dialog box is displayed again.


Now the riser knows that he has to click on the Select text button to select a text in the drawing.


The user can select any text. It doesn't matter how long the text is or what rotation angle it has. Here is an example.




The text is TEXT and it has been drawn under an angle of 30 degrees. Next a box is drawn around it. Here is how it looks.




As you can see. The box around the text has got the same angle as the text. And there is a spacing between the text and the box.


The AutoLISP Program And The DCL File


Normally I given the listing of the AutoLISP program in the second post. But this time I want to give it to you now.


Here is the AutoLISP program.


(defun c:txbox (/ di fl ht ip lg ls ra sp sl tx
vl
)
(start)
(setq ls (list "2" "3" "4" "5")
fl 2
)
(setq di (load_dialog "c:/make/txbox.dcl"))
(while (> fl 1)
(if (not (new_dialog "txbox" di))
(exit)
)
(start_list "space")
(mapcar 'add_list ls)
(end_list)
(action_tile "cancel" "(done_dialog 0)")
(action_tile "accept" "(setq vl (value))
(done_dialog 1)"
)
(action_tile "select" "(done_dialog 2)")
(setq fl (start_dialog))
(if (= fl 2)
(setq sl (entsel "\nSelect text: ")
tx (car sl)
)
)
(if (and (= fl 1) (null tx))
(progn
(alert "No text selected")
(setq fl 3)
)
)
)
(unload_dialog di)
(if (= fl 1)
(progn
(setq sp (atoi (nth (atoi vl) ls))
ls (fnddt tx)
ip (nth 0 ls)
lg (nth 1 ls)
ht (nth 2 ls)
ra (nth 3 ls)
)
(drbox ip sp lg ht ra)
)
)
(endpr)
)


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


(defun value (/ vl)
(setq vl (get_tile "space"))
vl
)


(defun seltx (/ tx)
(setq tx (car (entsel "\nSelect text: ")))
tx
)


(defun fnddt (tx / el ht ip lg ls ra v1 v2)
(setq el (entget tx)
ls (textbox el)
v1 (caar ls)
v2 (caadr ls)
lg (- v2 v1)
ip (cdr (assoc 10 el))
ht (cdr (assoc 40 el))
ra (cdr (assoc 50 el))
)
(list ip lg ht ra)
)


(defun drbox (ip sp lg ht ra)
(setq ip (polar ip (+ ra pi) sp)
ip (polar ip (- ra (* pi 0.5)) sp)
)
(command "line" ip
(setq ip (polar ip
ra
(+ lg (* sp 2))
)
)
(setq ip (polar ip
(+ ra
(* pi 0.5)
)
(+ ht
(* sp 2)
)
)
)
(polar ip
(+ ra pi)
(+ lg (* sp 2))
)
"c"
)
)


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


(c:txbox)


And here is the DCL file.


txbox : dialog
{
label = "Box Around Text";
: spacer
{
height=1;
}
: button
{
label = "Select text";
key = "select";
width = 12;
fixed_width = true;
alignment = centered;
height = 3;
}
: spacer
{
height=1;
}
: boxed_column
{
:popup_list
{
key = "space";
label = "Space";
edit_width = 2;
}
}
: spacer
{
height=1;
}
ok_cancel;
}


Next Post


In the next psot I will give an explanation of the AutoLISP file. You will also get an explanation of the DCL file.


Telling Others


Do you like what you have read? Do you know other people, that also could be interested in what I'm saying? 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.


YouTube


I have added videos to YouTube. The videos give examples of my AutoLISP programming work. You could engage me if you want.


If you are thinking of engaging me. Listen. I work for free. I write an AutoLISP program for you. You only pay when you are satisfied.


That is important. When you come to me with an AutoLISP programming job, you are not spending any money.


On YouTube you can find my videos here:


http://youtu.be/zgTWKo7DpeM
http://youtu.be/sd-sbyM3-d8
http://youtu.be/2yhk7G5KlAs
http://youtu.be/mEA6lymElqI
http://youtu.be/eyOdOTHPH-o
http://youtu.be/O8Zy6n9zS8Q
http://youtu.be/5sMBtfnnizk
http://youtu.be/QrmbXvmFa2o
http://youtu.be/4Ol-YpDC2MY
http://youtu.be/DWFke-Nie0E






































No comments:

Post a Comment