我无法抗拒:
(defun C:test ( / *error* dcl des dch dcf L r mann perc ChosenDiameters ) (defun *error* ( msg ) (and (< 0 dch) (unload_dialog dch)) (and (eq 'FILE (type des)) (close des)) (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) )) (princ) ); defun *error* (if (and ; write the dialog on the fly - temporary use (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w")) (princ (strcat "samp8 : dialog" "{ label = "Pipe Lines";" " : row" " { : boxed_column" " { label = "Pipe diameters used (mm)"; spacer;" " : list_box { key = "LB"; multiple_select = true; width = 10; height = 15; }" " }" " : boxed_column " " { label = "Variables";" " : edit_box { key = "eb1"; label = "Manning 'n'"; edit_width = 6 ; value = "0.013"; }" " : edit_box { key = "eb2"; label = "% part full"; edit_width = 6 ; value = "50"; }" " }" " }" " ok_cancel;" "}" ); strcat des ); princ (not (setq des (close des))) (setq dch (load_dialog dcl)) (new_dialog "samp8" dch) ); and (progn ; Populate the list_box tile: (start_list "LB") (mapcar 'add_list (setq L '("150" "200" "225" "250" "300" "375" "450" "600"))) (end_list) ; Set the first item as default value in the list box: (set_tile "LB" "0") ; Set default values - if ok is pressed without any input: (setq r (get_tile "LB")) (setq mann (get_tile "eb1")) (setq perc (get_tile "eb2")) ; Set default actions for the tiles: (action_tile "LB" "(setq r $value)") (action_tile "eb1" "(setq mann $value)") (action_tile "eb2" "(setq perc $value)") (action_tile "accept" "(done_dialog 1)") ; Store the result - if user pressed OK, dcf will be 1, else 0 (setq dcf (start_dialog)) ); progn ); if (*error* nil) ; unload, and erase the temporary dcl file ; Check if user pressed OK (if (= 1 dcf) (alert ; Display the results: (strcat "\nList of selected diameters: \n" (vl-prin1-to-string (setq ChosenDiameters (mapcar '(lambda (x) (nth x L)) (read (strcat "(" r ")"))))) "\nManning: " mann "\nPercentage: " perc ); strcat ); alert ); if (princ)); defun
当然要归功于李·麦克(但基本上我写的每一个DCL代码,他都隐藏在那个里——就我所知)。