;;;; copy right statement ;;;; ;;;; ;;;; ;;;; April, 2000, copyright by Takehiko Nagakura. All rights reserved. ;;;; ;;;; April, 2003, last modified. ;;;; ;;;; Written by takehiko nagakura, Massachusetts Institue of Technology. ;;;; ;;;; Do not use, copy, or distribute without permission by Takehiko ;;;; ;;;; Nagakura. Nagakura will not be responsible for any consequence ;;;; ;;;; of running this program. ;;;; ;;;; ;;;; ;;;; For information, send e-mail to takehiko@mit.edu ;;;; ;;;; ;;;; ;;;; For complete information about making dialog in AutoCAD, ;;;; Help>Developer Help>Conents>VisualLISP Developer's Guide>Chapter11-12 (Dialog Boxes) ;;;; Example ;;;; ;;;; This function takes a list of words and display them ;;;; in a dialog box. ;;;; To load this file successfully, you will need to have ;;;; an associated DCL definition file, "sample_dialog.dcl" ;;;; and have it placed in a directory that AutoCAD can find ;;;; automatically by including it in the Support File Search Path. ;;;; ;;;; Tools>Options>Files tab>Support File Search Path>add (defun c:choose_fruit ( / flag fruits) ;; First thing you need is to load the dialog definition file ;; which includes the kinds, positions, sizes and names of ;; elements in your dialog window. In this example, the dialog ;; includes a list box (of names), OK button and CANCEL button. (setq dcl_id (load_dialog "sample_dialog.dcl")) ;; The dialog definition file can have definitions of multiple ;; dialog windows. So, I will specify one of the dialogs now. ;; At this point, the dialog shows up in AutoCAD. If the dialog ;; definition cannot be found(the flag is nil), I will give up and exit. (setq flag (new_dialog "sample_dialog_A" dcl_id)) (if (null flag) (exit)) ;; After loading the dialog, you should define the content and ;; function of each element. ;;cancel button ;;(action_tile key macro) defines what happens when the ;;button is clicked. The button is the one marked by the key ;;in the dialog definition file. Macro should be a double ;;quoted expression, which will be executed when the button is ;;clicked. In this example, when the cancel button is clicked, ;;It will ;; 1) make the dialog disappear ;; 2) set the global variable *result* to be nil (action_tile "canceled" "(done_dialog) (setq *result* nil)") ;;scrolbable list ;;To add entries into the list, use the three commands, ;;(start_list key) (add_list name) (end_list) ;;Selecting a name does not do anything but hiliting the name. (setq fruits (list "apple" "orange" "banana" "lemon")) (start_list "name_list") (add_list (nth 0 fruits)) (add_list (nth 1 fruits)) (add_list (nth 2 fruits)) (add_list (nth 3 fruits)) (end_list) ;;ok button ;;See the function 'ok_action below. (action_tile "accepted" "(ok_action)") ;; Next, calling (start_dialog) will let the user interact with ;; the dialog window. This continues untill the user select one ;; of the buttons which executes (done_dialog). (start_dialog) ;; Unload the dialog file after all is done. (unload_dialog dcl_id) ;; This function returns the current value of 'result. ;; If the user clicked cancel, the value is nil. ;; If the user clicked OK, the value is the selected name in the list. (if *result* (nth *result* fruits) ) ;if ) ;; This defines what happens when the used clicks OK button. ;; It reads the value of the "name_list". The value is the ;; position of the name entry (the top one is 0) described ;; in a string. So, you will need to use "read" command ;; to translate the position into an integer. ;; *result* is a global variable which can be changed ;; by different functions. (defun ok_action () (setq *result* (read (get_tile "name_list"))) (done_dialog) ) (prompt "(c:choose_fruit)")