Documente Academic
Documente Profesional
Documente Cultură
acad_snap : dialog { label = "Drawing Aids"; : row { : column { : boxed_column { label = "Modes"; : toggle { label = "&Ortho"; key = "ortho"; } : toggle { label = "Solid &Fill"; key = "fill"; }
Key attribute identifies a text string that associates the dialog tile with an AutoLISP function
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 le contains standard prototype denitions. The acad.dcl le contains denitions for dialog boxes used by AutoCAD. Do not edit either one of these les! Altering them can cause AutoCADs built-in dialog boxes to crash.
To actually begin accepting input from the user, the AutoLISP (start_dialog) function 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 important 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. A sample custom dialog box.
Text item
DCL Tiles
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 arrangement 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; }
The text_part tile allows placement of text items in a dialog box. The value attribute 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 subassembly 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 { aspect_ratio = 0; label = "Viewpoint Presets"; fixed_height = true; fixed_width = true; : column { : row { : text { label = "Set Viewing Angles"; key = "ddvp_header"; } } : row { fixed_width = true; fixed_height = true; : image_button { alignment = top; fixed_width = true; fixed_height = true; key = "ddvp_image"; width = 39; height = 12; color = 0; is_tab_stop = false; } } : row { : button { label = "Set to Plan View"; key = "ddvp_set_plan"; mnemonic = "V"; } } }
Copyright by Goodheart-Willcox Co., Inc.
: row { : radio_row { : radio_button { label = "Absolute to WCS"; key = "ddvp_abs_wcs"; mnemonic = "W"; value = "1"; } : radio_button { label = "Relative to UCS"; key = "ddvp_rel_ucs"; mnemonic = "U"; } } }
spacer_1; ok_cancel_help_errtile; }
: row { : edit_box { label = "From: X Axis:"; mnemonic = "A"; key = "ddvp_val_x"; fixed_width = true; edit_width = 6; } : edit_box { label = "XY Plane:"; mnemonic = "P"; key = "ddvp_val_xyp"; fixed_width = true; edit_width = 6; } }
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
Complete the exercise on the student website.
www.g-wlearning.com/CAD
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 referenced. 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 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 character 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 entdel entmake entmod entsel entupd getangle getcorner getdist getint getkword getorient getpoint getreal getstring graphscr grclear grdraw grread grtext grvecs menucmd nentsel osnap prompt redraw ssget (interactive) textpage textscr
Exercise 29-2
Complete the exercise on the student website.
www.g-wlearning.com/CAD
and controlled by
EXAMPLE2.LSP. Mnemonic attribute is underlined
Copyright by Goodheart-Willcox Co., Inc.
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.
//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; } } }
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.
//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 Test
Answer the following questions. Write your answers on a separate sheet of paper or complete the electronic chapter test on the student 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.
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. Then, write the required DCL and AutoLISP files. A. Displays the current date. B. Displays the current time. C. Contains buttons to display and update current date and time. D. Displays the current drawing name. E. Contains an OK button.