Entering Edit Boxes
Dialog boxes have many different kinds
of visual means of showing and/or editing information. These are called
tiles. Tiles, in effect, have attributes (properties). The tile attributes
define the way tiles might react or may be shown by default. Some
attributes can be defined in the driving source code (AutoLisp) and others
in the dialog source code (DCL).
Attributes can also define the size or shape of tiles. The attribute that
we will discuss to allow the enter key to act as the "OK" button
is the allow_accept
attribute. This particular tile attribute is always defined in the DCL
file.
The DCL Coding shown below is the typical syntax for an edit
box :
: edit_box {
label = "some_label";
allow_accept = true_or_false;
width = tile_width;
edit_width = length_of_edit_box;
edit_limit = edit_limit_of_edit_box;
key = "key_name_for_driving_source_access";
mnemonic = "alt_key_for_easy_jump";
}
|
Everything in between the braces { } is
the edit box attributes. The allow_accept
attribute shown above shows true_or_false.
To set an edit box to allow the enter key to act as the "OK"
button set the allow_accept attribute
to be equal to true. If the attribute does not exist it may be added to
the DCL file.
Note: Omitting the allow_accept
attribute in dialog control syntax will leave the tile at allow_accept
= false by default.
Here's a practical example.
TRAJ2 : dialog {
label = "Conveyor Trajectory";
: edit_box {
label = "&Velocity (m/s)";
key = "VEL";
edit_width = 5;
allow_accept = true;
}
: edit_box {
label = "&Radius of Pulley (m)";
key = "RA";
edit_width = 5;
allow_accept = true;
}
: edit_box {
label = "&Angle of Incline";
key = "INC";
edit_width = 5;
allow_accept = true;
}
: edit_box {
label = "&Depth of Material (mm)";
key = "DEP";
edit_width = 5;
allow_accept = true;
}
ok_cancel ;
:text_part {
label = "Designed and Created";
}
:text_part {
label = "by Kenny Ramage";
}
}
|
Save this as TRAJ2.DCL. Now for the
AutoLisp coding :
;CODING BEGINS HERE
(defun C:TRAJ2 ()
(setq V 1.5
R 0.3
ang 8.0
MD 75.0
);setq
(setq dcl_id (load_dialog "TRAJ2.dcl"))
(if (not (new_dialog "TRAJ2" dcl_id))
(exit)
);if
(set_tile "VEL" "1.5")
(set_tile "RA" "0.3")
(set_tile "INC" "8.0")
(set_tile "DEP" "75.0")
(mode_tile "VEL" 2)
(action_tile
"cancel"
"(done_dialog) (setq userclick nil)"
)
(action_tile
"accept"
(strcat
"(progn (setq V (get_tile \"VEL\"))"
"(setq R (get_tile \"RA\"))"
"(setq ang (get_tile \"INC\"))"
"(setq MD (get_tile \"DEP\"))"
" (done_dialog)(setq userclick T))"
)
)
(start_dialog)
(unload_dialog dcl_id)
(if userclick
(alert (strcat "Velcocity = " V "\n"
"Radius = " R "\n"
"Angle = " ang "\n"
"Material Depth = " MD))
);if
(princ)
);defun
(princ)
;CODING ENDS HERE
|
Save this as TRAJ2.LSP. Now load and run
it. A dialog like this should appear :
Change any of the values in the edit
boxes. Now, whilst still in the edit box, press your "Enter"
key. The dialog closes and the rest of the program runs.
When you press the "Enter" key, because the edit box
tiles attribute "allow_accept" is
set to "true", the coding for the
tile which has the attribute "is_default"
(the "OK" tile) is triggered.
|