This example starts with a simple dialog box:
The following DCL defines the dialog box:
hello : dialog {
label = "Sample Dialog Box";
: text { label = "Hello, world."; }
ok_only;
}
This DCL defines a dialog box labeled Sample Dialog Box that contains a text tile and a single OK button. The DCL resides in a file named hello.dcl.
To display the dialog box and respond to the user pressing OK
- Use the load_dialog function
to load the DCL file into memory. For example:
(setq dcl_id (load_dialog "hello.dcl"))
The load_dialog function returns a DCL identification number. You need this to identify the dialog in subsequent function calls.
- Call the new_dialog function
and pass it the dialog name and DCL identification number as arguments,
as follows:
(new_dialog "hello" dcl_id)
- Initialize the dialog
box by setting up tile values, lists, and images.
The DCL example above uses a predefined tile named ok_only, so you do not have to initialize the tile unless you want to override its default values. The ok_only tile also has an action named done_dialog assigned to it. If the user presses the OK button, AutoCAD passes the done_dialog call to your AutoLISP application and ends the dialog.
- Call start_dialog to
pass control of the dialog to AutoCAD for display to the user:
(start_dialog)
- Call unload_dialog to
remove the dialog from memory after the user responds.
Steps 3, 4, and 5 are dependent on the new_dialog function returning a non-nil value. For the sake of simplicity, no error processing is included in this example.
You can use the following function to call the sample dialog box:
(defun C:HELLO( / dcl_id )
(setq dcl_id (load_dialog "hello.dcl")) ; Load the DCL file.
(if (not (new_dialog "hello" dcl_id)) ; Initialize the dialog.
(exit) ; Exit if this doesn't
; work.
)
(start_dialog) ; Display the dialog
; box.
(unload_dialog dcl_id) ; Unload the DCL file.
(princ)
)
Enter this code into a new VLISP text editor window and load the program by choosing Tools Load Text in Editor from the VLISP menu. To display the dialog box, enter (c:hello) at the VLISP Console prompt.
Note that the start_dialog call remains active until the user selects a tile (usually a button) whose associated action expression calls done_dialog. The done_dialog call can be issued explicitly by the tile. The done_dialog call is also issued by the selected tile if its is_cancel attribute is set to true.