@tpottebaum hi,
i see you already got good solutions but i would like upgrade this a little bit 😀
so here is my ARRAY-TEST command which includes (handle-dialog-box) function.
I assume you know that AutoLISP is based on Classic LISP and this means a programing language who works with lists and has many tools (functions) that manipulates lists. the thread you presented here is very much candidate to be manipulate by lists at least for the retrieving\setting of 6 edit_box values in from a dialog box.
First the whole code is encapsulated under the definition of (see line #3) c:array-test function inside all the declaration of local functions and variables, this protects them from interfering with other outside our command.
The program start at line #198 and on line #205 you see the call for (handle-dialog-box) which is what we interest on. at line #114 the function starts. a call to find array-test.dcl file is made and load the dialog in memory (see lines #116-117)
On line #120 a call to (init_setup) function where main data definition is made (see lines #11-38)
a variable keys-lst is set with all the keys name from the dialog box as a list (line #13)
on lines #16-25 a variable variables-lst is load with all the variables (exactly same as you declare them) but is hold in a list. to create this, i use (mapcar) & (lambda) functions which are key functions to build lists. what (mapcar) does is apply a function [on this case (lambda)] on a list of data items and actually the list holds the variables as quoted variables (i explain this next)
on line #26 a variable values-lst hold the initial values of the edit boxes.
on lines#28-38 a loop to set all 6 variables with the initial values from values-lst.
you declared all your variables as string, this is obvious as the data retrieved from dialog boxes all strings but eventually you need to convert them to be integers \ reals. In variables-lst i holds them as they should be integers & reals ready for the array.
about quoted variables:
a variable that declares as quote, can be set with (set) function, this known in lisp as indirect assignment. see line #31 and line #47.
bottom line after (init_setup) is done, variables-lst will be set with values-lst. the same as you did but much more lisp style
(vl-every) by the way is an AutoLISP function that applies a function [in this case (lambda)] on lists very similar to (mapcar). the different between them is (vl-every) return T if the applied function return T for all the items in the lists whereas (mapcar) return a list created from all returns values from each iteration of (lambda).
back to our code, line #124 you see a big (while) this control the appearance of the dialog box. a variable what_next initially set to 2 and depending on your dialog it could be any higher value. as long as what_next is higher then 1 the dialog will be reopen untill the user pick OK (what_next = 1) or Cancel (what_next = 0)
inside the (while) line #125 the dialog is open at center of screen
on line #131 a call to (set_tiles_values) to show the current variables-lst values.
on lines #41-55 implements (set_tiles_values)
cause our data is lists i again use (vl-every) to set the tiles. the huge advantage of (vl-every) [also (mapcar)] is it accepts lists as arguments (for the calling function lambda) as you can see on lines #52-53
on line #133-145 (vl-every) used again to defines the (action_tile) for the edit boxes. a functions (check_int_value) & (check_real_value) is called to validate the values, if it's under min & max values you can specify on the (action_tile) calls.
lines #149-150 covers the "accept" "cancel" buttons - this i assumes you already knows.
review (ctrl_accept) function to learn how the retrieve of the tiles is done.
on line #152 the call:
(setq what_next (start_dialog)) ; start dialog
after the dialog box is close, process continue on line #154
enjoy
Moshe
(vl-load-com) ; load activex support
(defun c:array-test (/ handle-dialog-box ; local function
p1 x1 y1 currentX ;| local variables |;)
(defun handle-dialog-box (/ init_setup set_tiles_values check_int_value check_real_value ctrl_accept ; local functions
keys-lst variables-lst values-lst dclfname dcl_id what_next ; local variables
numCols numRows colSpacing rowSpacing topEdgeSpacing bottomEdgeSpaceing ;| local variables |;)
; prepare variables before dialog open
(defun init_setup ()
; declare dialog keys
(setq keys-lst '("numCols" "numRows" "colSpacing" "rowSpacing" "topEdgeSpacing" "bottomEdgeSpacing"))
; declar dialog variables base on keys-lst
(setq variables-lst (mapcar
(function
(lambda (key)
(eval (quote (read key))) ; convert string to symbol\variable
)
); function
keys-lst
); mapcar
); setq
(setq values-lst '(23 8 16.0 16.0 9.0 9.0)) ; initial values
(vl-every
(function
(lambda (var val)
(set var val) ; indirect assignment
)
); function
; dialog variables
variables-lst
values-lst
); vl-evrey
); init_setup
(defun set_tiles_values ()
;; Set default values for the fields
(vl-every
(function
(lambda (key val)
(if (eq (type val) 'INT)
(set_tile key (itoa val))
(set_tile key (rtos val 2))
); if
); lambda
); function
keys-lst
values-lst
); vl-every
); set_tiles_value
(defun check_int_value (key val low high)
(if (not
(and
(numberp (atoi val))
(>= (atoi val) low) (<= (atoi val) high)
)
)
(progn
(vlr-beep-reaction)
(set_tile "error" "Invalid integer value.")
(mode_tile key 3)
); progn
(progn
(set_tile key (rtos (atoi val) 2 0))
(set_tile "error" "")
); progn
); if
); check_numeric_value
(defun check_real_value (key val low high)
(if (not
(and
(numberp (atof val))
(>= (atof val) low) (<= (atof val) high)
)
)
(progn
(vlr-beep-reaction)
(set_tile "error" "Invalid real value.")
(mode_tile key 3)
); progn
(progn
(set_tile key (rtos (atof val) 2))
(set_tile "error" "")
); progn
); if
); check_real_value
(defun ctrl_accept (/ i)
(setq i -1)
(vl-every
(function
(lambda (var key)
(set var (apply (if (<= (setq i (1+ i)) 1) 'atoi 'atof) (list (get_tile key))))
); lambda
); function
variables-lst
keys-lst
); vl-every
(done_dialog 1)
); ctrl_accept
; here start handle-dialog-box
(if (and
(setq dclfname (findfile "array-test.dcl")) ; get dcl file from supprt files search path
(setq dcl_id (load_dialog dclfname)) ; get dcl id
)
(progn
(init_setup) ; prepare variables before dialog open
(setq what_next 2)
(While (> what_next 1)
(if (not (new_dialog "array_test" dcl_id "" '(-1 -1))) ; open dialog
(exit)
)
; set tiles here, list, popup_list edit_box etc...
(set_tiles_values)
;; Define actions for dialog buttons
(vl-every
(function
(lambda (var key)
(if (eq (type (vl-symbol-value var)) 'INT)
(action_tile key "(check_int_value $key $value 1 99)")
(action_tile key "(check_real_value $key $value 0.1 99.9)")
)
); lambda
); function
variables-lst
keys-lst
); vl-every
;; Define actions for dialog buttons
(action_tile "accept" "(ctrl_accept)")
(action_tile "cancel" "(done_dialog 0)")
(setq what_next (start_dialog)) ; start dialog
(cond
((= what_next 1) ; user pick OK
; do your job after dialog is close
; ....
; ....
; print dialog edit-box values
(terpri)
(princ (mapcar
(function
(lambda (key var)
(cons key (vl-symbol-value var))
)
); function
keys-lst
variables-lst
)
); princ
); case
((= what_next 0) ; user pick cancel
; do cleanup
; .....
; .....
; .....
); case
((= what next 2) ; handle other code here
; .....
; .....
; reopen dialog?
); case
); cond
); while
(unload_dialog dcl_id)
); progn
); if
); handle-dialog-box
; here start c:array-test
(if (setq p1 (getpoint "\nSpecify starting point for the array: "))
(progn
(setq x1 (car p1) y1 (cadr p1))
(setq currentX x1 currentY y1)
;; Call the dialog box to get array configuration
(handle-dialog-box)
; do your array command here
; .....
; .....
; .....
); progn
); if
(princ)
); c:array-test
array_test : dialog {
label = "Array Configuration";
: boxed_column {
:edit_box {
label = "Number of Columns:\t\t\t\t\t";
key = "numCols";
edit_width = 7;
}
:edit_box {
label = "Number of Rows:\t\t\t\t\t\t\t\t\t\t\t";
key = "numRows";
edit_width = 7;
}
:edit_box {
label = "Horizontal Spacing:\t\t\t\t\t\t";
key = "colSpacing";
edit_width = 7;
}
:edit_box {
label = "Vertical Spacing:\t\t\t\t\t\t\t\t\t\t\t";
key = "rowSpacing";
edit_width = 7;
}
:edit_box {
label = "Top Edge Spacing:\t\t\t\t\t\t";
key = "topEdgeSpacing";
edit_width = 7;
}
:edit_box {
label = "Bottom Edge Spacing:";
key = "bottomEdgeSpacing";
edit_width = 7;
}
}// column
spacer_1;
ok_cancel_err;
}