The Autolisp Tutorial - DCL: Dialog Control Language - Part 5
The Autolisp Tutorial - DCL: Dialog Control Language - Part 5
}
: radio_button {
// Put code for radio_button 2 here
}
: radio_button {
// Put code for radio_button 3 here
}
: radio_button {
// Put code for radio_button 4 here
}
}
: boxed_row {
: button {
// Put code for the Okay button here
}
: button {
// Put code for the Cancel button here
}
}
}
Let's copy in the code for the header and all of the controls above from the
"Controls" section of this tutorial. I'll show them in red. Notice the key names
and labels had to be changed.
SAMPLE5 : dialog {
label = "Sample Dialog Box Routine - Part
5";
: column {
: radio_column {
key = "mychoice";
: radio_button {
key = "but1";
label = "Apples";
}
: radio_button {
key = "but2";
label = "Oranges";
}
: radio_button {
key = "but3";
label = "Bananas";
}
: radio_button {
key = "but4";
label = "Lemons";
}
}
: boxed_row {
: button {
key = "accept";
label = " Okay ";
is_default = true;
}
: button {
key = "cancel";
label = " Cancel ";
is_default = false;
is_cancel = true;
}
}
}
}
Right click and copy the above. Open NotePad and paste it. Save the file as
SAMPLE5.DCL Be sure to change the "Save as Type" drop down box to "All
Files" before saving it or it will put a ".txt" extension on the file name. Save
this file somewhere in the AutoCAD search path.
Next we will get a copy of the AutoLisp model and revise it. All new code is
shown in red.
(defun C:SAMPLE5()
;;;--- Load the dcl file from disk into memory
(if(not(setq dcl_id (load_dialog "SAMPLE5.dcl")))
(progn
(alert "The DCL file could not be loaded!")
(exit)
)
Right click and copy the above. Open NotePad and paste it. Save the file as
SAMPLE5.LSP Be sure to change the "Save as Type" drop down box to "All
Files" before saving it or it will put a ".txt" extension on the file name. Save
this file somewhere in the AutoCAD search path.
Let's load the program and see what the DCL file looks like. On the command
line type this:
Command: (load "sample5") and press enter
You should see this
C:Sample5
Command:
Now type Sample5 and press enter. If everything went according to plan you
should see this on your screen:
That doesn't look very good does it? Let's change the boxed_row into
a boxed_column in our DCL file. (See the blue text in the DCL file above) Make
the changes then Save the Sample5.DCL file. No need to load the autolisp
program again, it's loaded. Just run the Sample5 program again. Now it should
look like this:
It still doesn't look right. It's our label "Sample Dialog Box Routine - Part 5"
that is causing the problem. Let's shorten it to "SDBR - Part 5" and try it again:
Looks better!
Looking good so far. We need to add the SaveVars function to save the
selected items from the radio_column when the Okay button is pressed. Look at
the blue text in the Sample5.lsp program above.
Let's steal the saveVars routine from the radio_column control on the "Saving
data from the dialog box" page of this tutorial and modify it. I'll show the
modifications in red.
We can do this two different ways. We can check each radio_button to find out
which one is on or we can check the entire column of radio_buttons by getting
the value of the radio_column.
First method: Checking the Radio_Column:
(defun saveVars()
;;;--- Get the key of the choice made
;;;
[ returns "but1" "but2" "but3" or "but4" whichever
is selected.]
(setq myChoice(get_tile "mychoice"))
)
Second method: Checking each Radio_Button:
(defun saveVars()
;;;--- Get the value of each item
(setq choice1(atoi(get_tile "but1")))
chosen
(setq choice2(atoi(get_tile "but2")))
(setq choice3(atoi(get_tile "but3")))
(setq choice4(atoi(get_tile "but4")))
; 0 = not chosen
1=
; 0 = not chosen
; 0 = not chosen
; 0 = not chosen
1 = chosen
1 = chosen
1 = chosen
So...Which one do we use? For this tutorial, let's use both. Why not?
(defun saveVars()
;;;--- Get the key of the choice made
;;;
[ returns "but1" "but2" "but3" or "but4" whichever
is selected.]
(setq myChoice(get_tile "mychoice"))
;;;--- Get the value of each item
(setq choice1(atoi(get_tile "but1")))
chosen
(setq choice2(atoi(get_tile "but2")))
(setq choice3(atoi(get_tile "but3")))
(setq choice4(atoi(get_tile "but4")))
)
; 0 = not chosen
1=
; 0 = not chosen
; 0 = not chosen
; 0 = not chosen
1 = chosen
1 = chosen
1 = chosen
Add this to the original Sample5.lsp program and we should have something that
looks like this:
(defun saveVars()
;;;--- Get the key of the choice made
;;;
[ returns "but1" "but2" "but3" or "but4" whichever
is selected.]
(setq myChoice(get_tile "mychoice"))
;;;--- Get the value of each item
(setq choice1(atoi(get_tile "but1")))
chosen
(setq choice2(atoi(get_tile "but2")))
(setq choice3(atoi(get_tile "but3")))
(setq choice4(atoi(get_tile "but4")))
; 0 = not chosen
1=
; 0 = not chosen
; 0 = not chosen
; 0 = not chosen
1 = chosen
1 = chosen
1 = chosen
)
(defun C:SAMPLE5()
;;;--- Load the dcl file from disk into memory
(if(not(setq dcl_id (load_dialog "SAMPLE5.dcl")))
(progn
(alert "The DCL file could not be loaded!")
(exit)
)
;;;--- Else, the DCL file was loaded
(progn
;;;--- Load the definition inside the DCL file
(if (not (new_dialog "SAMPLE5" dcl_id))
(progn
(alert "The DCL definition could not be loaded!")
(exit)
)
;;;--- Else, the definition was loaded
(progn
;;;--- If an action event occurs, do this function
(action_tile "accept" "(saveVars)(done_dialog 2)")
Last item. We need to replace the line in the program: (princ "\n The
user pressed Okay!") with something to display the selected item.
;;;--- If the user pressed the Okay button
(if(= ddiag 2)
(progn
;;;--- Inform the user of his selection using the
radio_column data
(princ "\n Using Radio_column data...You chose ")
(cond
((= myChoice "but1")(princ "Apples!"))
((= myChoice "but2")(princ "Oranges!"))
((= myChoice "but3")(princ "Bananas!"))
Add the above to the autolisp file, save it and test it out. Everything working
okay?
When you get your program tested and everything is working, move the blue
line above, [ (defun C:SAMPLE5() ] all the way to the top of the file. This will
make all of your variables local and will reset them all to nil when the program
ends.
That's it. We're done.
cancelar los botones en una fila en la parte inferior del cuadro de dilogo.As
que ... voy a necesitar algo como esto:
: Columna {
: radio_column {
// cdigo para radio_column
Ponga aqu
: radio_column { // cdigo para poner
radio_button 1 aqu
}
: radio_button { //
cdigo para radio_button Ponga aqu 2
}
:
radio_button { // cdigo para radio_button Ponga aqu
3
}
: radio_button { // Dicho cdigo para
radio_button 4 aqu
}
}
: {boxed_row
:
botn {
Sample5: Dilogo {
label = "Muestra el cuadro de dilogo de
rutina - Parte 5";
: {columna
: radio_column {
key = " mychoice ";
: radio_button {
key = " But1 ";
label = " Manzanas ";
}
{: radio_button
= clave " but2 ";
label = " Naranjas ";
}
: radio_button {
key = " but3 ";
label = " Bananas ";
}
: radio_button {
key = " but4 ";
label = " Limones ";
}
}
: boxed_row {
: botn {
clave =
"aceptar";
label = "Est
bien";
is_default =
true;
}
: botn
{
key = "cancelar";
label = "Cancelar";
is_default =
false;
is_cancel = true;
}
}
}
}
Haga clic derecho y copiar la anterior. Abra el Bloc de notas y
pegarlo. Guarde el archivo como SAMPLE5.DCL Asegrese de cambiar la
opcin "Guardar como tipo" cuadro desplegable a "todos los archivos" antes
de guardarlo o se ponga una extensin ".txt" en el nombre del
archivo. Guarde este archivo en algn lugar de la ruta de bsqueda de
AutoCAD.
(progn
( alertar "El sample5 definicin no se pudo cargar!
")
(salida)
)
;;; --- Si no, la definicin se carg
(progn
;;; --- Si se produce un evento de
accin, hacer esta funcin
(action_tile "aceptar"
" (saveVars) (done_dialog 2) ")
(action_tile
"cancelar" "(done_dialog 1)")
;;; --- Muestra el
cuadro de dilogo
(setq ddiag
(start_dialog))
;;; --- Descargue el cuadro de
dilogo
( dcl_id unload_dialog)
;;; --Si el usuario pulsa el botn Cancelar
(si (= ddiag
1)
(princ "\ n sample5 cancelado! ")
)
;;; --- Si el usuario pulsa el botn
Aceptar
(si ( = ddiag 2)
(progn
(princ "\ n El usuario pulsa Okay!")
)
)
)
)
)
)
;;; --- reprimir
el ltimo eco para una salida limpia
(princ) )
Se ve mejor!
Verse bien hasta el momento. Tenemos que aadir los SaveVars funcin para
guardar los elementos seleccionados de la radio_column cuando se pulsa el botn
Aceptar. Mira el texto azul en el programa Sample5.lsp arriba.
Vamos a robar la rutina saveVars del control radio_column en el " Guardar datos
desde el dilogo cuadro"pgina de este tutorial y modificarlo. Te voy a mostrar
las modificaciones en rojo.
Podemos hacerlo de dos maneras diferentes. Podemos comprobar cada
radio_button para averiguar cul es el o podemos comprobar toda la columna de
radio_buttons al obtener el valor de la radio_column.
As que ... Cul usamos? Para este tutorial, vamos a usar ambos. Por que no?
(SaveVars defun ()
;;; --- Obtener la clave de la eleccin hecha
;;; [Regresa " But1 "" but2 "" but3 "o" but4 "lo que se ha
seleccionado.]
(Setq miOpcion (get_tile " mychoice "))
;;; --- Obtener el valor de cada elemento
(Choice1 setq (atoi (get_tile " But1 "))) ; 0 = No 1 = elegidos
elegidos
(eleccin2 setq (atoi (get_tile " but2 "))) ; 0 = No 1 = elegidos
elegidos
(choice3 setq (atoi (get_tile " but3 ")))
elegidos
(choice4 setq (atoi (get_tile " but4 ")))
elegidos
; 0 = No 1 = elegidos
; 0 = No 1 = elegidos
(progn
( alertar "La definicin DCL no se pudo cargar!")
(salida)
)
;;; --- Si no, la definicin se carg
(progn
;;; --- Si se produce un evento de
accin, hacer esta funcin
(action_tile "aceptar"
"(saveVars) (done_dialog 2)")
(action_tile
"cancelar" "(done_dialog 1)")
;;; --- Muestra el
cuadro de dilogo
(setq ddiag
(start_dialog))
;;; --- Descargue el cuadro de
dilogo
( dcl_id unload_dialog)
;;; --Si el usuario pulsa el botn Cancelar
(si (= ddiag
1)
(princ "\ n sample5 signi
llen! ")
)
;;; --- Si el usuario pulsa el botn
Aceptar
(si (= ddiag 2)
(progn (princ
"\ n El usuario pulsa Okay!")
)
)
)
)
)
)
;;; --- reprimir el ltimo
eco para una salida limpia
(princ) )