Beruflich Dokumente
Kultur Dokumente
Introduction to
Dialog Control
Language (DCL)
Learning Objectives
After completing this chapter, you will be able to:
Describe the types of files that control dialog boxes.
Define the components of a dialog box.
Write a DCL file for a basic dialog box.
Write an AutoLISP file to control a dialog box.
Associate an action with a dialog box tile.
DCL
DCL F
File
ille F
Formats
orm
matss
A DCL file is formatted as an ASCII text file with a .dcl file extension. These files
can have any valid file name, but a file name with 1 to 8 characters is recommended.
Writing DCL is easy. Many of the components of a DCL file are normal English words.
The components of a dialog boxsuch as edit boxes, images, and drop-down lists
are referred to as tiles. Tiles are defined by specifying various attribute values. Each
attribute controls a specific property of the tile, such as size, location, and default values.
CAUTION
The base.dcl file contains standard prototype definitions. The acad.dcl
file contains definitions for dialog boxes used by AutoCAD. Do not
edit either one of these files! Altering them can cause AutoCADs
built-in dialog boxes to crash.
AutoLISP
Auto
oLISP aand
nd D
DCL
CL
A DCL file simply defines a dialog box. The dialog box cannot actually do anything
without a controlling application. AutoLISP is frequently used to control dialog sessions.
This section shows examples using the AutoLISP dialog-handling functions.
In order to display a dialog box, the controlling AutoLISP application must first
load the dialog definition. The AutoLISP (load_dialog) function loads the specified
dialog definition file:
(load_dialog "file name.dcl")
The file name is enclosed in quotation marks. The (load_dialog) function returns a
positive integer that identifies the loaded DCL file. If the attempted load was unsuc-
cessful, a negative integer is returned.
The next step is to activate a specific dialog box definition contained within the
DCL file. The AutoLISP (new_dialog) function activates the dialog box specified, where
dlgname is the name of the dialog box:
(new_dialog dlgname dcl_id)
This function is case sensitive. Suppose the dialog definition is named main. Specifying
Main or MAIN will not activate this dialog box since the text string does not exactly
match. The dcl_id argument represents the integer value returned by (load_dialog).
Figure 29-3.
Some of the tile definitions and attributes associated with the Viewpoint Presets dialog box
(this dialog box is no longer defined by a DCL file).
ddvpoint : dialog { : row {
aspect_ratio = 0; : radio_row {
label = "Viewpoint Presets"; : radio_button {
fixed_height = true; label = "Absolute to WCS";
fixed_width = true; key = "ddvp_abs_wcs";
: column { mnemonic = "W";
: row { value = "1";
: text { }
label = "Set Viewing Angles"; : radio_button {
key = "ddvp_header"; label = "Relative to UCS";
} key = "ddvp_rel_ucs";
} mnemonic = "U";
}
: row { }
fixed_width = true; }
fixed_height = true;
: image_button {
alignment = top;
: row {
fixed_width = true;
: edit_box {
fixed_height = true;
label = "From: X Axis:";
key = "ddvp_image";
mnemonic = "A";
width = 39;
key = "ddvp_val_x";
height = 12;
fixed_width = true;
color = 0;
edit_width = 6;
is_tab_stop = false;
}
}
: edit_box {
}
label = "XY Plane:";
: row { mnemonic = "P";
: button { key = "ddvp_val_xyp";
label = "Set to Plan View"; spacer_1; fixed_width = true;
key = "ddvp_set_plan"; ok_cancel_help_errtile; edit_width = 6;
mnemonic = "V"; } }
} }
}
}
Exercise 29-1
1. Use the examples in the text to create EXAMPLE1.DCL and EXAMPLE1.LSP. Create
each file in the Visual LISP Editor.
2. Load the AutoLISP program file to test the files. The dialog box should automati-
cally open and remain displayed until you pick the OK button.
Associating
A sssociaating
g Fu
Functions
uncttio
onss wit
with
th Ti
Tiles
iless
Most tiles can be associated with actions. These actions vary from run-time error
checking to performing tasks outside of the dialog box session. The (action_tile)
AutoLISP function provides the basic means of associating tiles with actions.
(action_tile "key" "action-expression")
The key references the attribute assigned in the DCL file. The action-expression is
the AutoLISP expression performed when the action is called. When the desired action
requires a large amount of AutoLISP code, it is best to define a function to perform the
required tasks. This function is then called within the action-expression. Both the key
and action-expression arguments are supplied as text strings.
In order to access a specific tile from AutoLISP, the key of the tile must be refer-
enced. The key is specified as an attribute in the DCL file. Tiles that are static (no
associated action) do not require keys. Any tile that must be referenced in any way
such as setting or retrieving a value, associating an action, or enabling/disabling the
tilerequires a key.
The next example changes the previous dialog box by adding a button that displays
the current time when picked. The new or changed DCL code is shown in color. Save
this file as EXAMPLE2.DCL.
main : dialog {
label = "Dialog Box Example 2";
: text_part {
value = "";
key = "time";
}
: button {
key = "update";
label = "Display Current Time";
mnemonic = "C";
}
ok_only;
}
Notice the addition of a key attribute to the text_part tile. This allows access by
the AutoLISP application while the dialog box is open. Another addition is the
button tile. A key attribute is provided in the button tile so an association can be
created in the AutoLISP program with an action-expression argument. The label
attribute provides the text displayed on the button. The mnemonic attribute
Exercise 29-2
1. Use the examples in the text to create EXAMPLE2.DCL and EXAMPLE2.LSP. Load
and run the AutoLISP program. What happens when the time button is picked?
Figure 29-4.
The dialog box
defined by
EXAMPLE2.DCL
and controlled by
EXAMPLE2.LSP. Label attribute
Mnemonic attribute from button tile
is underlined
Dialog Example 3
Create the following DCL and AutoLISP programs. Save the programs as
EXAMPLE3.DCL and EXAMPLE3.LSP. Then, load the AutoLISP program file. To open
the dialog box, type DRAW. The dialog box is shown in Figure 29-5.
;EXAMPLE3.LSP
;This file displays the dialog box defined in EXAMPLE3.DCL and begins the
; selected drawing command as specified by the user.
;
(defun C:DRAW (/ EX3_DCL_ID)
(setq EX3_DCL_ID (load_dialog "EXAMPLE3.DCL"))
(if (not (new_dialog "draw" EX3_DCL_ID))
(exit)
)
(action_tile "line" "(setq CMD $key) (done_dialog)")
(action_tile "circle" "(setq CMD $key) (done_dialog)")
(action_tile "arc" "(setq CMD $key) (done_dialog)")
(action_tile "cancel" "(setq CMD nil) (done_dialog)")
(start_dialog)
(unload_dialog EX3_DCL_ID)
(command CMD)
)
Figure 29-5.
The dialog box
displayed using the
EXAMPLE3.DCL and
LSP files.
;;EXAMPLE4.LSP
;;
(defun CHECKOUT ()
(setq LD (tblsearch "LAYER" (nth (atoi (get_tile "lyr_pop")) LL))
LN (cdr (assoc 2 LD))
LS (cdr (assoc 70 LD))
)
(if (and
(/= 1 LS)
(/= 65 LS)
)
(progn
(setvar "CLAYER" (nth (atoi (get_tile "lyr_pop")) LL))
(done_dialog)
)
(alert "Selected layer is frozen!")
) )
(defun C:GOFOR ()
(setq EX4_DCL_ID (load_dialog "EXAMPLE4.DCL"))
(if (not (new_dialog "fourth" EX4_DCL_ID)) (exit))
(start_list "lyr_pop")
(setq LL '()
NL (tblnext "LAYER" T)
IDX 0
)
(while NL
(if (= (getvar "CLAYER") (cdr (assoc 2 NL)))
(setq CL IDX)
(setq IDX (1+ IDX))
)
(setq LL (append LL (list (cdr (assoc 2 NL))))
NL (tblnext "LAYER")
) )
(mapcar 'add_list LL)
(end_list)
(set_tile "lyr_pop" (itoa CL))
(action_tile "lyr_pop" "(if (= $reason 4) (mode_tile \"accept\" 2))")
(action_tile "accept" "(CHECKOUT)")
(start_dialog)
(unload_dialog EX4_DCL_ID)
(princ)
)
Figure 29-6.
The dialog box
displayed using the
EXAMPLE4.DCL and
LSP files.
Chapter Review
Answer the following questions. Write your answers on a separate sheet of paper
or complete the electronic chapter review on the companion website.
www.g-wlearning.com/CAD
1. What are the two types of files that must be created to construct a functioning
dialog box?
2. When referring to a dialog box, what is a tile?
3. When defining a dialog or tile, inside of which character are all of the required
attributes for a tile definition placed?
4. Which symbol indicates a comment inside of a DCL file?
5. Write the appropriate notation for the first line of a DCL file that defines a dialog
box named Test.
6. Write the appropriate notation in a DCL file that defines the text in the title bar of
a dialog box named Select Application.
7. Write the notation in a DCL file for defining a cluster of four buttons labeled OK,
Next, Cancel, and Help.
8. Write the notation that would appear in a LSP file that loads a dialog file named
PICKFILE.
9. What is a key in a DCL file?
10. Write the proper DCL file notation for the first line that identifies a button.
2. Create a dialog box that contains the following items. Write the required DCL and
AutoLISP files.
A. Title barDate
B. LabelCurrent Date:
C. Action buttonDisplay Current Date
D. Contains an OK button.
3. Create a dialog box that performs the following tasks. Write the required DCL and
AutoLISP files.
A. Displays the current date.
B. Displays the current time.
C. Contains buttons to display and update the current date and time.
D. Displays the current drawing name.
E. Contains an OK button.