Friday, January 10, 2014

Another AutoLISP And DCL Program 2


Introduction


Now I'm going to talk about the AutoLISP file and the DCL file. I will start with talking about the DCL file.


The DCL File


Here is the DCL file. It is not really complicated. See how the ALIGNMENT attributes and the SPACER attributes are used.


selpt : dialog
{
label = "Select Point";
: boxed_column
{
label = "Sample Point";
: spacer
{
height=1;
}
: button
{
label = "Pick Point <";
key = "hide";
width = 12;
fixed_width = true;
mnemonic = "P";
alignment = centered;
}
: spacer
{
height=1;
}
: edit_box
{
key = "px";
label = "&X:";
width = 8;
fixed_width = true;
alignment = centered;
}
: edit_box
{
key = "py";
label = "&Y:";
width = 8;
fixed_width = true;
alignment = centered;
}
: edit_box
{
key = "pz";
label = "&Z:";
width = 8;
fixed_width = true;
alignment = centered;
}
: spacer
{
height=1;
}
}
: spacer
{
height=1;
}
ok_cancel;
}


In the DCL file a button is specified and there are three edit boxes in the dialog box file. You see what text is displayed.


You can also see what the keys of the button and the text boxes are. The AutoLISP program makes a reference to them.


The AutoLISP Program


Here is the AutoLISP program. I did not follow what was given by AFRALISP. Their program has no functions. My version has.


(defun c:selp ()
(start)
(setq px "0.000"
py "0.000"
pz "0.000"
fl 4
)
(setq di (load_dialog "c:/make/selpt.dcl"))
(while (> fl 2)
(if (not (new_dialog "selpt" di))
(exit)
)
(sttle px py pz)
(action_tile "cancel" "(done_dialog 1)")
(action_tile "accept"
"(setq px (get_tile \"p1\"))
(setq py (get_tile \"p2\"))
(setq pz (get_tile \"p3\"))
(done_dialog 2)"
)
(action_tile "hide" "(done_dialog 4)")
(setq fl (start_dialog))
(if (= fl 4)
(progn
(setq ls (selpt)
px (nth 0 ls)
py (nth 1 ls)
pz (nth 2 ls)
)
)
)
)
(unload_dialog di)
(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 sttle (px py pz)
(set_tile "px" px)
(set_tile "py" py)
(set_tile "pz" pz)
)


(defun selpt ()
(setq selpoint (getpoint
"\nInsertion Point: "
)
)
(setq px (rtos (car selpoint) 2 4))
(setq py (rtos (cadr selpoint) 2 4))
(setq pz (rtos (caddr selpoint) 2 4))
(list px py pz)
)


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


(c:selp)


I have added the following functions to the program:


1. START
2. STTLE
3. SELPT
4. ENDPR


You already know about the first and the last function. So I don't have to give an explanation about them.


As the AutoLISP program starts, a call is made to the START function. You know what is done by the START function.


Next start values are given to the following three variables:


PX
PY
PZ


The variables get the value “0.000”.


The FL variable gets the value. That variable is used for the WHILE function, that comes next. If continues as long as the value is more than two.


Before the WHILE function is started the dialog box is loaded into the AutoLISP program. It isn't displayed yet.


In the WHILE function the dialog box is displayed. And the PX, PT, and PZ tile get the value that has been given to the variables.


That is done with the second function. It is done with the STTLE function. That function is used again and again.


Next ACTION_TILE functions are used. Those functions are used as there is clicked on one of the buttons.


There can be clicked on the CANCEL button, on the OK button, or on the PICK Point button. These are the keys of the buttons:


Button
Key




CANCEL
CANCEL
OK
ACCEPT
PICK POINT
HIDE


DONE_DIALOG is given a value. The value depends on the button that has been clicked. These are the values:


Button
Value




CANCEL
0
OK
1
PICK POINT
4


If there has been clicked on the PICK Point button, then a point is picked in the screen. And a new value for PX, PY, and PZ is found.


We come again to the STTLE function. And the new values are given to the PX, PY, and PZ tiles. And they are displayed in the dialog box.


After clicking on the PICK POINT button, the FL value is given the value 4. So we stay in the WHILE loop.


If there is clicked on the CANCEL button or the OK button, then the FL variable gets the value zero or one. There is jumped out of the WHILE loop.


When there is jumped out of the WHILE loop, then the AutoLISP program ends. No so if there is clicked on the PICK POINT button.


OK. This is the explanation of the AutoLISP program. Now you know how the AutoLISP program works. I hope it is clear.


But that is the most important part. Now you have seen how you can perform an AutoLISP action if a dialog box is displayed.


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