Sie sind auf Seite 1von 12

Chapter

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.

Programmable dialog boxes can be used to completely customize the interface


of AutoLISP programs. These dialog boxes allow LISP programs to work like many
of AutoCADs built-in functions. Using dialog boxes improves efficiency and reduces
data-entry errors.
Dialog boxes minimize the amount of typing required by the user. Rather than
answering a series of text prompts on the command line, the user selects options from
the dialog box. Dialog box fields can be filled in by the user in any order. While the
dialog box is still active, the user can revise values as necessary.
AutoLISP provides basic tools for controlling dialog boxes, but the dialog box itself
must be defined using the Dialog Control Language (DCL). The definition is written
to an ASCII file with a .dcl file extension. When creating and editing DCL files, the
Visual LISP Editor provides many helpful tools, including color coding.
This chapter is only an introduction to DCL. It covers basic DCL file construction and
a few common tile types. For more information, refer to the online help documentation.

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.

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 733
When writing a DCL file, you do not use parentheses as you do with AutoLISP.
When defining a dialog box or tile, all of the required attributes are placed within
{braces}. As with AutoLISP programs, indentation helps to separate individual
elements, making the file more readable. Comments are preceded by two forward
slashes (//). Semicolons are used at the end of an attribute definition line.
To view an example of DCL code, open the acad.dcl and base.dcl files in a text
editor. These two files are found in the users \Support folder, not the AutoCAD \Support
folder. A portion of the acad.dcl file is shown in Figure 29-1.

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-1. acad_snap : dialog {


A portion of the Dialog definition
label = "Drawing Aids";
acad.dcl file. : row {
: column { Label attribute
: boxed_column { adds a text string
label = "Modes";
: toggle {
label = "&Ortho";
key = "ortho";
Key attribute
}
identifies a text string
: toggle {
that associates the dialog
label = "Solid &Fill";
tile with an AutoLISP
key = "fill";
function
}

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 734
This value is often assigned to a variable, as you will see later. The (new_dialog) func-
tion also supports additional, optional arguments, which are not discussed here.
To actually begin accepting input from the user, the AutoLISP (start_dialog) func-
tion must be used:
(start_dialog)
This function has no arguments. It allows input to be received from the dialog box
initialized by the previous (new_dialog) expression.
With these basic AutoLISP functions, it is possible to display the dialog box shown in
Figure 29-2. You will create this dialog box in the next section. After the AutoLISP program
is written and saved, it can be loaded into AutoCAD using the load function or the APPLOAD
command. Enter the controlling AutoLISP application named EXAMPLE1.LSP as follows.
(setq EX1_DCL_ID (load_dialog "EXAMPLE1.DCL"))
(if (not (new_dialog "main" EX1_DCL_ID))
(exit)
)
(start_dialog)
Now, take a closer look at the controlling code for this dialog box:
(setq EX1_DCL_ID (load_dialog "EXAMPLE1.DCL"))
(if (not (new_dialog "main" EX1_DCL_ID))
(exit)
)
(start_dialog)
This expression loads the dialog definition found in EXAMPLE1.DCL and assigns the
value returned by (load_dialog) to the variable EX1_DCL_ID.
(setq EX1_DCL_ID (load_dialog "EXAMPLE1.DCL"))
(if (not (new_dialog "main" EX1_DCL_ID))
(exit)
)
(start_dialog)
If (new_dialog) is unable to activate the specified dialog box for any reason, the
expression in the next three lines exits (terminates) the application. This is an impor-
tant safety feature. In many cases, loading an incorrect or incomplete definition can
cause your system to lock up and may require the system to be rebooted.
(setq EX1_DCL_ID (load_dialog "EXAMPLE1.DCL"))
(if (not (new_dialog "main" EX1_DCL_ID))
(exit)
)
(start_dialog)
The last expression opens the dialog box indicated by the previous (new_dialog) expression.
Once the descriptions within a specific DCL file are no longer needed, they can be
removed from memory using the AutoLISP (unload_dialog) function.
(unload_dialog dcl_id)
Do not unload a dialog definition until your application is finished using the DCL
file. Otherwise, your application may fail to properly function.

Figure 29-2. Text item Title bar


A sample custom
dialog box. Predefined
button

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 735
DCL
DC
CL T
Tiles
illes
Your work in AutoCAD has provided you with a good background in how dialog
boxes function. By now, you should be familiar with the use of buttons, edit boxes,
radio buttons, and list boxes. This will be helpful as you design dialog interfaces for
your AutoLISP programs.
DCL tiles are used individually or combined into structures called clusters. For
example, a series of button tiles can be placed in a column tile to control the arrange-
ment of the buttons in the dialog box. The primary tile is the dialog box itself.
The best way to begin understanding the format of a DCL file is to study a simple
dialog box definition. The following DCL code defines the dialog box shown in Figure 29-2.
main : dialog {
label = "Dialog Box Example 1";
: text_part {
value = "This is an example.";
}
ok_only;
}
Now, take a closer look at the definition of this dialog box. The dialog definition
is always the first tile definition.
main : dialog {
label = "Dialog Box Example 1";
: text_part {
value = "This is an example.";
}
ok_only;
}
Everything within the braces defines the features of the dialog box. The word main
indicates the name of the dialog box within the code. This name is referenced by the
controlling AutoLISP application. A colon (:) precedes all tile callouts. In the case of a
dialog tile, the colon separates the name from the tile callout.
main : dialog {
label = "Dialog Box Example 1";
: text_part {
value = "This is an example.";
}
ok_only;
}
The label attribute of the dialog tile controls the text that appears in the title bar
of the dialog box. The line is terminated with a semicolon. All attribute lines must be
terminated with a semicolon.
main : dialog {
label = "Dialog Box Example 1";
: text_part {
value = "This is an example.";
}
ok_only;
}

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 736
The text_part tile allows placement of text items in a dialog box. The value attri-
bute is used to specify the text that is displayed. Just as with the dialog tile, all of the
attributes are defined between braces.
main : dialog {
label = "Dialog Box Example 1";
: text_part {
value = "This is an example.";
}
ok_only;
}
There are many predefined tiles and subassemblies in the base.dcl file. A subas-
sembly is a cluster of predefined tiles, such as ok_cancel and ok_help. The ok_only
tile places an OK button at the bottom of the dialog box, as shown in Figure 29-2. The
statement is not preceded by a colon because it is not a specific definition. This line is
terminated with a semicolon, just like an attribute. Braces are not required because the
statement is a reference to a predefined tile, rather than a tile definition.
Once you have defined a dialog box, the definition must then be saved in a DCL file.
For this example, the dialog definition above should be saved in the file EXAMPLE1.DCL.
This is treated as any other support file and should be saved in the AutoCAD support path.
For examples of other DCL functions, look at the Viewpoint Presets dialog box shown
in Figure 29-3. Various tiles of this dialog box are identified with the corresponding

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"; } }
} }
}
}

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 737
DCL code needed to define the tile. In older releases of AutoCAD, this dialog box was
defined by a stand-alone DCL file named ddvpoint.dcl. However, this DCL file no longer
exists as the dialog box is now defined by a different method.

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

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 738
underlines the specified letter within the label to allow keyboard access. The
AutoLISP application used to manage this dialog session is as follows. Save the
program as EXAMPLE2.LSP.
(setq EX2_DCL_ID (load_dialog "EXAMPLE2.DCL"))
(if (not (new_dialog "main" EX2_DCL_ID))
(exit)
)
(defun UPDTILE ()
(setq CDVAR (rtos (getvar "CDATE") 2 16)
CDTXT (strcat "Current Time: "
(substr CDVAR 10 2)
":"
(substr CDVAR 12 2)
":"
(substr CDVAR 14 2)
)
)
(set_tile "time" CDTXT)
)
(UPDTILE)
(action_tile "update" "(UPDTILE)")
(start_dialog)
The dialog box displayed by this code is shown in Figure 29-4. The time
button displays the current time when the button is picked. The mnemonic char-
acter is displayed once the [Alt] key is pressed. Note: Some AutoLISP functions not
covered in this text are used in the above programming to retrieve and display the
current time.
Commands that change the display or require user input (outside of the dialog
box interface) cannot be used while a dialog box is active. These AutoLISP functions
cannot be used with DCL:
command getangle getpoint grread prompt
entdel getcorner getreal grtext redraw
entmake getdist getstring grvecs ssget (interactive)
entmod getint graphscr menucmd textpage
entsel getkword grclear nentsel textscr
entupd getorient grdraw osnap

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

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 739
Working
Work
kin
ng with
witth DCL
DCL
There are many types of DCL tiles available. You can provide edit boxes for users
to directly enter information, such as numeric or text information. You can create lists
and drop-down lists to allow users to choose from preset selections. You can also add
buttons to provide a simple means of initiating an action.
Images can be used to enhance dialog boxes. For example, you can place company
or personal logos in your dialog boxes. An interactive image, such as the one that
appears in the Viewpoint Presets dialog box shown in Figure 29-3, can also be used.
Tools such as text tiles, sliders, and clusters are used to control the layout of tiles in a
dialog box.
A wide variety of attributes are available for controlling the appearance and
function of a dialog session. In addition, several AutoLISP functions are provided
to control your dialog session. You can disable or enable tiles and change the active
tile. It is even possible to change the value or state of a tile based on an entry in
another tile.
You have already seen two examples of dialog boxes created using DCL and
AutoLISP. The following sections provide two additional applications that use various
dialog boxes. Study these examples for additional insight into the creation of dialog
boxes. Be sure to have an appropriate reference handy, such as the online documenta-
tion, to look up DCL and AutoLISP terms. You can adapt or modify these programs to
produce dialog sessions of your own.

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.

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 740
//EXAMPLE3.DCL
//Defines a dialog box that presents three drawing options to the user.
//
draw : dialog {
label = "Select Drawing Option";
: text_part {
label = "Select object type to draw: ";
}
: row {
: button {
key = "line";
label = "Line";
mnemonic = "L";
fixed_width = true;
}
: button {
key = "circle";
label = "Circle";
mnemonic = "C";
fixed_width = true;
}
: button {
key = "arc";
label = "Arc";
mnemonic = "A";
fixed_width = true;
}
: button {
key = "cancel";
label = "Cancel";
is_cancel = true;
fixed_width = true;
}
}
}

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 741
Dialog Example 4
This example allows you to select a new current layer from a drop-down list in a
dialog box. Save the files as EXAMPLE4.DCL and EXAMPLE4.LSP. Then, load the AutoLISP
file. To access the dialog box, type GOFOR. The dialog box is shown in Figure 29-6.

;;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.

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 742
//EXAMPLE4.DCL
// Presents a list of layers to the user.
fourth : dialog {
label = "Select Layer";
: popup_list {
label = "New Current Layer:";
mnemonic = "N";
key = "lyr_pop";
allow_accept = true;
width = 32;
}
ok_cancel;
}

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.

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 743
Drawing Problems
1. Create a dialog box that contains the following items. Write the required DCL and
AutoLISP files.
A. Title barDialog Box Test
B. LabelThis is a test.
C. Contains an OK 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.

Drawing Problems - Chapter 29

Copyright by Goodheart-Willcox Co., Inc.


Chapter 29 Introduction to Dialog Control Language (DCL) AutoCAD and Its ApplicationsAdvanced 744

Das könnte Ihnen auch gefallen