Tharwat Posted April 18, 2012 Posted April 18, 2012 Hello . When there are tow popup lists in a dialog , and we would like to get the value of the second popup list , the following get_tile function would consider the first list as 0 and the second one 's value (action_tile "accept" "(setq size1 (atoi (get_tile \"h1\")))(setq size2 (atoi (get_tile \"h2\")))") How to get the value of the second popup list since the first list is not active and although it has a value of 0 Quote
Tharwat Posted April 18, 2012 Author Posted April 18, 2012 Example ... DCL code .. txt: dialog { label = "texts"; : column { : row { :boxed_column { :radio_button { key = "rad1"; label = "50-500" ; } :radio_button { key = "rad2"; label = "500-1000" ; } } :boxed_column { :row {: popup_list { key = "h1"; is_enabled = true; }} :row {: popup_list { key = "h2"; is_enabled = false;}} }} : boxed_row { : button { key = "accept"; label = " Okay "; is_default = true; } : button { key = "cancel"; label = " Cancel "; is_default = false; is_cancel = true;} } } } Lisp code ... (defun c:Test (/ dcl_id lst1 lst2 val1 val2 size1 size2) (setq dcl_id (load_dialog "txt.dcl")) (if (not (new_dialog "txt" dcl_id)) (exit) ) (start_list "h1") (mapcar 'add_list (setq lst1 '("50" "75" "100" "125" "150" "200" "250" "300" "350" "400" "450" "500" ) ) ) (end_list) (start_list "h2") (mapcar 'add_list (setq lst2 '("550" "600" "650" "700" "750" "800" "850" "900" "950" "1000" ) ) ) (end_list) (set_tile "rad1" "1") (action_tile "rad1" "(setq val1 $value)(mode_tile \"h1\" (boole 1 1 0))(mode_tile \"h2\" (boole 1 1 (atoi val1)))" ) (action_tile "rad2" "(setq val2 $value)(mode_tile \"h2\" (boole 1 1 0))(mode_tile \"h1\" (boole 1 1 (atoi val2)))" ) (action_tile "accept" "(setq size1 (atoi (get_tile \"h1\")))(setq size2 (atoi (get_tile \"h2\")))(setq done t)(done_dialog)" ) (action_tile "cancel" "(setq done nil)(done_dialog)") (start_dialog) (unload_dialog dcl_id) (if done (progn (princ (eval size1)) [color=red][b];;<= would always have a value , even if it was not chosen ( activated ) [/b][/color] (princ (eval size2)) ) ) (princ) ) Quote
MSasu Posted April 18, 2012 Posted April 18, 2012 (edited) You should test the state of the field (enabled / disabled): (defun OnOK() (if (= (get_tile "rad1") "1") (setq size1 (atoi (get_tile "h1"))) (setq size2 (atoi (get_tile "h2"))) ) (setq done t) (done_dialog) ) (action_tile "accept" "(OnOK)") Also, try to don't overcrowd the action's expression on ACTION_TILE; use a dedicated function instead. Edited April 18, 2012 by MSasu Spelling Quote
Tharwat Posted April 18, 2012 Author Posted April 18, 2012 Thanks Mircea . I tried that before , but it does always return a nil value , i mean the get_tile functions . (get_tile "rad1"); nil (get_tile "h1") ; nil (get_tile "h2"); nil Quote
Tharwat Posted April 18, 2012 Author Posted April 18, 2012 Test the code and will notice the return value to command line would be nil . (defun c:Test (/ dcl_id lst1 lst2 val1 val2 size1 size2) (setq dcl_id (load_dialog "txt.dcl")) (if (not (new_dialog "txt" dcl_id)) (exit) ) (start_list "h1") (mapcar 'add_list (setq lst1 '("50" "75" "100" "125" "150" "200" "250" "300" "350" "400" "450" "500" ))) (end_list) (start_list "h2") (mapcar 'add_list (setq lst2 '("550" "600" "650" "700" "750" "800" "850" "900" "950" "1000" ))) (end_list) (set_tile "rad1" "1") (action_tile "rad1" "(setq val1 $value)(mode_tile \"h1\" (boole 1 1 0))(mode_tile \"h2\" (boole 1 1 (atoi val1)))" ) (action_tile "rad2" "(setq val2 $value)(mode_tile \"h2\" (boole 1 1 0))(mode_tile \"h1\" (boole 1 1 (atoi val2)))" ) (defun OnOK () (cond ((= (get_tile "rad1") 1) (setq size1 (nth (atoi (get_tile "h1")) lst1))) ((= (get_tile "rad2") 1) (setq size1 (nth (atoi (get_tile "h2")) lst2))) ) (setq done t) (done_dialog) ) (action_tile "accept" "(OnOK)") (action_tile "cancel" "(setq done nil)(done_dialog)") (start_dialog) (unload_dialog dcl_id) [color=red][b] (print size1)[/b][/color] (princ) ) Quote
MSasu Posted April 18, 2012 Posted April 18, 2012 This should do what you expect: (cond ((= (get_tile "rad1") [color=red]"[/color]1[color=red]"[/color]) (setq size1 (nth (atoi (get_tile "h1")) lst1))) ((= (get_tile "rad2") [color=red]"[/color]1[color=red]"[/color]) (setq size1 (nth (atoi (get_tile "h2")) lst2))) ) Quote
Tharwat Posted April 18, 2012 Author Posted April 18, 2012 the value of the get_tile function would be a string , so we should test it with a string and not a number like this .. (= (get_tile "rad1") [color=red][b]"1"[/b][/color]) Quote
Tharwat Posted April 18, 2012 Author Posted April 18, 2012 Thanks for your time and for your precious help Mircea . Highly appreciated . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.