mhy3sx Posted November 7 Share Posted November 7 Hi I want to update a DCL lisp I want to add a pull down menu in the dcl file with two options 1) Option 1 2) Option 2 In Option 1 t1 = (/ (+ (* e 2.5) 75) 1.24)) and t2 = 322.58 In Option2 t1 = (/ (+ (* e 2.75) 85) 1.24)) and t2 = 354.84 (defun c:test (/ *error* dch dcl des a) (defun *error* ( msg ) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch) ) (if (= 'file (type des)) (close des) ) (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl) ) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (cond ( (not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w") ) ) (princ "\nUnable to open DCL for writing.") ) ( (progn (foreach str '( "ed : edit_box" "{" " alignment = left;" " width = 20;" ;" edit_width = 10;" ;" fixed_width = true;" "}" "" "peacost : dialog" "{" " spacer;" " key = \"dcl\";" " : row" " {" " : ed { key = \"a\"; label = \"Area:\"; }" " : ed { key = \"res1\"; label = \"Calc:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Text :\"; is_enabled = false; }" " }" " spacer;" " : row" " {" " : column { width = 10;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calc\"; is_default = true;" " is_cancel = false; fixed_width = true; width = 10; }" " }" ; end column " : column { width = 17;" " : button { key = \"OK\"; label = \"OK\"; is_default = true;" " is_cancel = true; fixed_width = true; width = 10; }" " }" ; end column " }" ; end row "}" ) (write-line str des) ) (setq des (close des) dch (load_dialog dcl) ) (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ( (not (new_dialog "peacost" dch)) (princ "\nUnable to display 'peacost' dialog.") ) (t (set_tile "dcl" "Any name") (action_tile "a" "(setq a $value)") (action_tile "cal" (vl-prin1-to-string '( (lambda ( / x) (set_tile "res1" "") (set_tile "res2" "") (setq t2 322.58) (cond ((or (not a) (= "" a)) (alert "xxxxxxxxxxxxx !!!") (mode_tile "a" 2) ) ((not (setq e (distof a))) (alert "xxxxxxxxxxxxxx!!!") (mode_tile "a" 2) ) ((<= e 250) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((and (> e 250) (<= e 1000)) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((> e 1000) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ) ; end cond ) ) ) ) (start_dialog) ) ) (*error* nil) (princ) ); end defun Can any one help me? Thanks Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 7 Author Share Posted November 7 Any idea how to add a pull down menu in the dcl dialog ? Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 7 Share Posted November 7 Not sure what is a pull down menu ? A dcl can have various methods Radio Buttons, Toogles, edit box, List box. You can also do Child dcls these pop up over the top of current dcl for say more choices. Can you post some form of image about what you want. PS a pull down menu is known as a POP menu ie the menu options that sit at the top of your screen. Can not have in a dcl. Quote Link to comment Share on other sites More sharing options...
dexus Posted November 8 Share Posted November 8 I think what you need is a PopUp_List: http://www.jefferypsanders.com/autolisp_DCL_Part4.html Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 8 Author Share Posted November 8 Hi BIGAL. I want to add "pull down menu" like the Image with two options 1) Option 1 2) Option 2 In Option 1 t1 = (/ (+ (* e 2.5) 75) 1.24)) and t2 = 322.58 In Option2 t1 = (/ (+ (* e 2.75) 85) 1.24)) and t2 = 354.84 In the image have days , I want option 1 and option2 . Thanks Quote Link to comment Share on other sites More sharing options...
Steven P Posted November 8 Share Posted November 8 (edited) Copying and pasting from my LISPs, something like this in the DCL coding: " :column { width = 5;" " : text { key = \"File\"; label = \"List Title\"; width = 5; alignment = left;}" " }" " :column { width = 22;" " :popup_list { key = \"DCLList\"; width = 20; multiple_select = true ; alignment = left; }" " }" and then where you set tiles something like this: (setq MyList '("A" "B" "C" "D" "E")) (start_list "DCLList" 3)(mapcar 'add_list MyList)(end_list);;create Lisp files list You can just add the list '("A" "B" ....) in the mapcar MyList part but I find it easier to set up the list first and then add it later Edited November 8 by Steven P Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 8 Author Share Posted November 8 OK " :column { width = 5;" " : text { key = \"File\"; label = \"Select Option\"; width = 5; alignment = left;}" " }" " :column { width = 22;" " :popup_list { key = \"DCLList\"; width = 20; multiple_select = true ; alignment = left; }" " }" (setq MyList '("Option1" "Option2")) (start_list "DCLList" 3)(mapcar 'add_list MyList)(end_list);;create Lisp files list And how to use different syntax for eatch option? In Option 1 t1 = (/ (+ (* e 2.5) 75) 1.24)) and t2 = 322.58 In Option2 t1 = (/ (+ (* e 2.75) 85) 1.24)) and t2 = 354.84 Thanks Quote Link to comment Share on other sites More sharing options...
Steven P Posted November 8 Share Posted November 8 You can use action tile to grab when the drop down list has changed and use get_tile which will give you the position you selected ("Option 1" will give 0, "Option 2" will give 1 for example) and from there do an if or cond to work out what you need to know. Something like this (action_tile "DCLList" "(setq MyAnswer (read (get_tile \"DCLList\"))) (If (= MyAnswer 0)(setq T1 123.456 T2 789.012 ) ; end setq ) ; end if " ) Quote Link to comment Share on other sites More sharing options...
Steven P Posted Friday at 04:37 PM Share Posted Friday at 04:37 PM (edited) overall something like this, update the action tile for the drop down as required. You might want to set the value of T1 and T2 to position a default value in case the user doesn't select anything in the drop down, or have the first item in the list a blank text "" (you can set the drop down list selection to something when you start the DCL, say "C" is the most common option, have that as default... so set the values to this default before you start) (defun c:test (/ *error* dch dcl des a T1 T2) (defun *error* ( msg ) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch) ) ; end if (if (= 'file (type des)) (close des) ) ; end if (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl) ) ; end if (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) ; end if (princ) ) ; end defun (cond ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w") ) ; end setq ) ; end not (princ "\nUnable to open DCL for writing.") ) ; end cond 'not' ((progn (foreach str '( "ed : edit_box" "{" " alignment = left;" " width = 20;" ;; " edit_width = 10;" ;; " fixed_width = true;" "}" "" "peacost : dialog" "{" " spacer;" " key = \"dcl\";" " : row" " {" " : ed { key = \"a\"; label = \"Area:\"; }" " : ed { key = \"res1\"; label = \"Calc:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Text :\"; is_enabled = false; }" " }" " spacer;" " : row {" ;;ADDED THESE LINES " :column { width = 5;" " : text { key = \"File\"; label = \"List Title\"; width = 5; alignment = left;}" " }" ; end column " :column { width = 22;" " :popup_list { key = \"DCLList\"; width = 20; multiple_select = true ; alignment = left; }" " }" ; end column " }" ; end row ;; TO HERE " : row" " {" " : column { width = 10;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calc\"; is_default = true;" " is_cancel = false; fixed_width = true; width = 10; }" " }" ; end column " : column { width = 17;" " : button { key = \"OK\"; label = \"OK\"; is_default = true;" " is_cancel = true; fixed_width = true; width = 10; }" " }" ; end column " }" ; end row "}" ) ; end str list (write-line str des) ) ; end foreach (setq des (close des) dch (load_dialog dcl) ) ; end str (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ( (not (new_dialog "peacost" dch)) (princ "\nUnable to display 'peacost' dialog.") ) ; end cond (t (set_tile "dcl" "Any name") (setq MyList '("A" "B" "C" "D" "E")) ;; ADDED THIS LINE (start_list "DCLList" 3)(mapcar 'add_list MyList)(end_list);;create Lisp files list ;; ADDED THIS LINE (action_tile "a" "(setq a $value)") (action_tile "DCLList" "(setq MyAnswer (read (get_tile \"DCLList\"))) ;; ADDED THIS LINE (If (= MyAnswer 0)(setq T1 123.456 ;; ADDED THIS LINE T2 789.012 ;; ADDED THIS LINE ) ; end setq ;; ADDED THIS LINE ) ; end if ;;ADDED THIS LINE " ;; ADDED THIS LINE ) ;; ADDED THIS LINE (action_tile "cal" (vl-prin1-to-string '( (lambda ( / x) (set_tile "res1" "") (set_tile "res2" "") (setq t2 322.58) (cond ((or (not a) (= "" a)) (alert "xxxxxxxxxxxxx !!!") (mode_tile "a" 2) ) ((not (setq e (distof a))) (alert "xxxxxxxxxxxxxx!!!") (mode_tile "a" 2) ) ((<= e 250) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((and (> e 250) (<= e 1000)) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((> e 1000) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ) ; end cond ) ) ) ) (start_dialog) ) ) (*error* nil) (princ T1) ) Edited Friday at 04:40 PM by Steven P Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted Friday at 06:58 PM Author Share Posted Friday at 06:58 PM Hi Steven P . Something is missing for the code In Option 1 t1 = (/ (+ (* e 2.5) 75) 1.24)) and t2 = 322.58 In Option2 t1 = (/ (+ (* e 2.75) 85) 1.24)) and t2 = 354.84 The t1 is not the same in option 1 (/ (+ (* e 2.5) 75) 1.24)) in option2 (/ (+ (* e 2.75) 85) 1.24)) and the t2 In Option 1 t2 = 322.58 In Option2 t2 = 354.84 Thanks Quote Link to comment Share on other sites More sharing options...
Steven P Posted Friday at 08:01 PM Share Posted Friday at 08:01 PM In the above I've only put in a few details as an example of how you could add in a drop down box - but like all CAD there are many ways to do the same thing. use the above to learn from. In your specific example I'd do something like this though: Add a default value to 'MyAnswer' early in the LISP to avoid errors later, value 0 - the first item in the drop down list In the drop down list only set MyAnswer to the position of the selection. If you use the default above there is no error if the user does nothing with the list Continue in the routing using the value of MyAnswer to set t1 and t2 where they are used and set - below using an if comment but if the drop down is longer, use conds. (defun c:test (/ *error* dch dcl des a MyAnswer t1 t2) (defun *error* ( msg ) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch) ) ; end if (if (= 'file (type des)) (close des) ) ; end if (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl) ) ; end if (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) ; end if (princ) ) ; end defun (setq MyAnswer 1) ;; Initial condition (cond ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w") ) ; end setq ) ; end not (princ "\nUnable to open DCL for writing.") ) ; end cond 'not' ((progn (foreach str '( "ed : edit_box" "{" " alignment = left;" " width = 20;" ;; " edit_width = 10;" ;; " fixed_width = true;" "}" "" "peacost : dialog" "{" " spacer;" " key = \"dcl\";" " : row" " {" " : ed { key = \"a\"; label = \"Area:\"; }" " : ed { key = \"res1\"; label = \"Calc:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Text :\"; is_enabled = false; }" " }" " spacer;" " : row {" ;;ADDED THESE LINES " :column { width = 5;" " : text { key = \"File\"; label = \"List Title\"; width = 5; alignment = left;}" " }" ; end column " :column { width = 22;" " :popup_list { key = \"DCLList\"; width = 20; multiple_select = true ; alignment = left; }" " }" ; end column " }" ; end row ;; TO HERE " : row" " {" " : column { width = 10;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calc\"; is_default = true;" " is_cancel = false; fixed_width = true; width = 10; }" " }" ; end column " : column { width = 17;" " : button { key = \"OK\"; label = \"OK\"; is_default = true;" " is_cancel = true; fixed_width = true; width = 10; }" " }" ; end column " }" ; end row "}" ) ; end str list (write-line str des) ) ; end foreach (setq des (close des) dch (load_dialog dcl) ) ; end str (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ( (not (new_dialog "peacost" dch)) (princ "\nUnable to display 'peacost' dialog.") ) ; end cond (t ;;Set DCL Tile values (set_tile "dcl" "Any name") (setq MyList '("Option 1" "Option 2" "D" "E")) (start_list "DCLList" 3)(mapcar 'add_list MyList)(end_list) ;;DCL Actions (action_tile "a" "(setq a $value)") (action_tile "DCLList" "(setq MyAnswer (read (get_tile \"DCLList\")))" ) (action_tile "cal" (vl-prin1-to-string '( (lambda ( / x) (set_tile "res1" "") (set_tile "res2" "") (if (= MyAnswer 1) (setq t2 354.84) ;;option 2 (setq t2 322.58) ;; everything else ) (cond ((or (not a) (= "" a)) (alert "xxxxxxxxxxxxx !!!") (mode_tile "a" 2) ) ((not (setq e (distof a))) (alert "xxxxxxxxxxxxxx!!!") (mode_tile "a" 2) ) ((<= e 250) (if (= MyAnswer 1) (setq t1 (/ (+ (* e 2.75) 85) 1.24)) ;;option 2 (setq t1 (/ (+ (* e 2.5) 75) 1.24)) ;; everything else ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((and (> e 250) (<= e 1000)) (if (= MyAnswer 1) (setq t1 (/ (+ (* e 2.75) 85) 1.24)) ;;option 2 (setq t1 (/ (+ (* e 2.5) 75) 1.24)) ;; everything else ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((> e 1000) (if (= MyAnswer 1) (setq t1 (/ (+ (* e 2.75) 85) 1.24)) ;;option 2 (setq t1 (/ (+ (* e 2.5) 75) 1.24)) ;; everything else ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ) ; end cond ) ) ) ) (start_dialog) ) ) (*error* nil) ) 1 Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted Friday at 09:36 PM Author Share Posted Friday at 09:36 PM Thanks Steven P. The code works fine. I want to ask another question . If I understand correct if option2 then --> (setq t1 (/ (+ (* e 2.75) 85) 1.24)) unless this --> (setq t1 (/ (+ (* e 2.5) 75) 1.24)) I see in the code (setq MyList '("Option 1" "Option 2" "D" "E")) If I have (setq MyList '("Option 1" "Option 2" "Option 3" "Option 4")) And in option 1 (/ (+ (* e 2.5) 75) 1.24)) in option 2 (/ (+ (* e 2.75) 85) 1.24)) in option 3 (/ (+ (* e 2.85) 95) 1.24)) in option 4 (/ (+ (* e 2.45) 75) 1.24)) and the t2 In Option 1 t2 = 322.58 In Option 2 t2 = 354.84 In Option 3 t2 = 384 In Option 4 t2 = 400 How to update the code. The question is how to update the code for more of two options? Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted Saturday at 03:52 AM Share Posted Saturday at 03:52 AM My take on the task is a little different I use a dcl I have 2 columns and make choices. I have to go right now but will come back with example. This is what I would have dcl look like with your option1 option2 option3 option4 etc Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted Saturday at 08:44 AM Author Share Posted Saturday at 08:44 AM Hi BIGAL. I am tryin to avoid to duplicate the code an use two or three radio butttons for eatch option. If I have the the radio buttons how to update the code to work for all options without copy the code two or three times (one for each option)? Because the core of the code is the same , only the t1 and t2 change. Thats why I ask a "pull down menu". Thanks Quote Link to comment Share on other sites More sharing options...
Steven P Posted Saturday at 02:18 PM Share Posted Saturday at 02:18 PM Yes, look at the code, hoping it is all there to look through and you can make changes as necessary. MyList list can be extended, shortened and adjusted to suit. The variable MyAnswer is the position of the selection in the drop down list (here Option 1 -> 0, Option 2 ->2 and so on). At the start of the code MyAnswer is set to a default (above it is 1, for Option 2, adjust to suit), for example you can change this part: (if (= MyAnswer 1) (setq t1 (/ (+ (* e 2.75) 85) 1.24)) ;;option 2 (setq t1 (/ (+ (* e 2.5) 75) 1.24)) ;; everything else ) to a series of IF statements, (If (= MyAnswer 0)....), (If (= MyAnswer 1)....), ..... or use a COND statement. Above I was assuming only 2 options, the value of T1 and T2 are either or, you just need to expand that to include for more options Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted Saturday at 02:56 PM Author Share Posted Saturday at 02:56 PM (edited) Hi Steven P, I am not sure I understand correct. I try this and move pop list in the top of the dcl, but I think is not working correct in all options (defun c:test (/ *error* dch dcl des a MyAnswer t1 t2) (defun *error* ( msg ) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch) ) ; end if (if (= 'file (type des)) (close des) ) ; end if (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl) ) ; end if (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) ; end if (princ) ) ; end defun (setq MyAnswer 1) ;;option 1 (setq MyAnswer 2) ;;option 2 (setq MyAnswer 3) ;;option 3 (setq MyAnswer 4) ;;option 4 (cond ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w") ) ; end setq ) ; end not (princ "\nUnable to open DCL for writing.") ) ; end cond 'not' ((progn (foreach str '( "ed : edit_box" "{" " alignment = left;" " width = 20;" ;; " edit_width = 10;" ;; " fixed_width = true;" "}" "" "peacost : dialog" "{" " spacer;" " key = \"dcl\";" " : row " ;;ADDED THESE LINES " {" " :column { width = 5;" " : text { key = \"File\"; label = \"List Title\"; width = 5; alignment = left;}" " }" ; end column " :column { width = 22;" " :popup_list { key = \"DCLList\"; width = 20; multiple_select = true ; alignment = left; }" " }" ; end column " }" ; end row ;; TO HERE " spacer;" " : row" " {" " : ed { key = \"a\"; label = \"Area:\"; }" " : ed { key = \"res1\"; label = \"Calc:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Text :\"; is_enabled = false; }" " }" " spacer;" " : row" " {" " : column { width = 10;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calc\"; is_default = true;" " is_cancel = false; fixed_width = true; width = 10; }" " }" ; end column " : column { width = 17;" " : button { key = \"OK\"; label = \"OK\"; is_default = true;" " is_cancel = true; fixed_width = true; width = 10; }" " }" ; end column " }" ; end row "}" ) ; end str list (write-line str des) ) ; end foreach (setq des (close des) dch (load_dialog dcl) ) ; end str (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ( (not (new_dialog "peacost" dch)) (princ "\nUnable to display 'peacost' dialog.") ) ; end cond (t ;;Set DCL Tile values (set_tile "dcl" "Any name") (setq MyList '("Option 1" "Option 2" "Option 3" "Option 4")) (start_list "DCLList" 3)(mapcar 'add_list MyList)(end_list) ;;DCL Actions (action_tile "a" "(setq a $value)") (action_tile "DCLList" "(setq MyAnswer (read (get_tile \"DCLList\")))" ) (action_tile "cal" (vl-prin1-to-string '( (lambda ( / x) (set_tile "res1" "") (set_tile "res2" "") (if (= MyAnswer 1) ;;option 1 (setq t2 322.58) ) (if (= MyAnswer 2) ;;option 2 (setq t2 354.84) ) (if (= MyAnswer 3) ;;option 3 (setq t2 384) ) (if (= MyAnswer 4) ;;option 4 (setq t2 400) ) (cond ((or (not a) (= "" a)) (alert "xxxxxxxxxxxxx !!!") (mode_tile "a" 2) ) ((not (setq e (distof a))) (alert "xxxxxxxxxxxxxx!!!") (mode_tile "a" 2) ) ((<= e 250) (if (= MyAnswer 1) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) ;;option 1 ) (if (= MyAnswer 2) (setq t1 (/ (+ (* e 2.75) 85) 1.24)) ;;option 2 ) (if (= MyAnswer 3) (setq t1 (/ (+ (* e 2.85) 95) 1.24)) ;;option 3 ) (if (= MyAnswer 4) (setq t1 (/ (+ (* e 2.45) 75) 1.24)) ;;option 4 ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((and (> e 250) (<= e 1000)) (if (= MyAnswer 1) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) ;;option 1 ) (if (= MyAnswer 2) (setq t1 (/ (+ (* e 2.75) 85) 1.24)) ;;option 2 ) (if (= MyAnswer 3) (setq t1 (/ (+ (* e 2.85) 95) 1.24)) ;;option 3 ) (if (= MyAnswer 4) (setq t1 (/ (+ (* e 2.45) 75) 1.24)) ;;option 4 ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ((> e 1000) (if (= MyAnswer 1) (setq t1 (/ (+ (* e 2.5) 75) 1.24)) ;;option 1 ) (if (= MyAnswer 2) (setq t1 (/ (+ (* e 2.75) 85) 1.24)) ;;option 2 ) (if (= MyAnswer 3) (setq t1 (/ (+ (* e 2.85) 95) 1.24)) ;;option 3 ) (if (= MyAnswer 4) (setq t1 (/ (+ (* e 2.45) 75) 1.24)) ;;option 4 ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "text text text") ) ) ; end cond ) ) ) ) (start_dialog) ) ) (*error* nil) ) Thanks Edited Saturday at 03:16 PM by mhy3sx Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted Saturday at 07:28 PM Author Share Posted Saturday at 07:28 PM I try this but is not working Gives me Quote Error: incorrect type - nil (defun c:test (/ *error* dch dcl des a MyAnswer t1 t2) (defun *error* (msg) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch) ) (if (= 'file (type des)) (close des) ) (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl) ) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) ;; Initial value for MyAnswer (setq MyAnswer nil) (cond ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w"))) (princ "\nUnable to open DCL for writing.") ) ((progn (foreach str '( "ed : edit_box" "{" " alignment = left;" " width = 20;" "}" "" "peacost : dialog" "{" " spacer;" " key = \"dcl\";" " : row" " {" " : column { width = 5;" " : text { key = \"File\"; label = \"List Title\"; width = 5; alignment = left; }" " }" " : column { width = 22;" " : popup_list { key = \"DCLList\"; width = 20; multiple_select = false; alignment = left; }" " }" " }" " spacer;" " : row" " {" " : ed { key = \"a\"; label = \"Area:\"; }" " : ed { key = \"res1\"; label = \"Calc:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Text :\"; is_enabled = false; }" " }" " spacer;" " : row" " {" " : column { width = 10; }" " : column { width = 17;" " : button { key = \"cal\"; label = \"Calc\"; is_default = true; is_cancel = false; fixed_width = true; width = 10; }" " }" " : column { width = 17;" " : button { key = \"OK\"; label = \"OK\"; is_default = true; is_cancel = true; fixed_width = true; width = 10; }" " }" " }" "}" ) (write-line str des) ) (setq des (close des) dch (load_dialog dcl)) (<= dch 0)) (princ "\nUnable to load DCL file.") ) ((not (new_dialog "peacost" dch)) (princ "\nUnable to display 'peacost' dialog.") ) (t ;; Set DCL Tile values (set_tile "dcl" "Any name") (setq MyList '("Option 1" "Option 2" "Option 3" "Option 4")) (start_list "DCLList" 3) (mapcar 'add_list MyList) (end_list) ;; DCL Actions (action_tile "a" "(setq a $value)") (action_tile "DCLList" "(setq MyAnswer (get_tile \"DCLList\"))") (action_tile "cal" (vl-prin1-to-string '( (lambda (/ x) (set_tile "res1" "") (set_tile "res2" "") (if MyAnswer (cond ((= MyAnswer "Option 1") (setq t2 322.58)) ;; Option 1 ((= MyAnswer "Option 2") (setq t2 354.84)) ;; Option 2 ((= MyAnswer "Option 3") (setq t2 384)) ;; Option 3 ((= MyAnswer "Option 4") (setq t2 400)) ;; Option 4 ) ) (cond ((or (not a) (= "" a)) (alert "Please enter the area!") (mode_tile "a" 2)) ((not (setq e (distof a))) (alert "The area must be a number!") (mode_tile "a" 2)) ((<= e 250) (setq t1 (cond ((= MyAnswer "Option 1") (/ (+ (* e 2.50) 75) 1.24)) ;; Option 1 ((= MyAnswer "Option 2") (/ (+ (* e 2.75) 85) 1.24)) ;; Option 2 ((= MyAnswer "Option 3") (/ (+ (* e 2.85) 95) 1.24)) ;; Option 3 ((= MyAnswer "Option 4") (/ (+ (* e 2.45) 75) 1.24)) ;; Option 4 )) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "Text text text")) ((and (> e 250) (<= e 1000)) (setq t1 (cond ((= MyAnswer "Option 1") (/ (+ (* e 2.50) 75) 1.24)) ;; Option 1 ((= MyAnswer "Option 2") (/ (+ (* e 2.75) 85) 1.24)) ;; Option 2 ((= MyAnswer "Option 3") (/ (+ (* e 2.85) 95) 1.24)) ;; Option 3 ((= MyAnswer "Option 4") (/ (+ (* e 2.45) 75) 1.24)) ;; Option 4 )) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "Text text text")) ((> e 1000) (setq t1 (cond ((= MyAnswer "Option 1") (/ (+ (* e 2.50) 75) 1.24)) ;; Option 1 ((= MyAnswer "Option 2") (/ (+ (* e 2.75) 85) 1.24)) ;; Option 2 ((= MyAnswer "Option 3") (/ (+ (* e 2.85) 95) 1.24)) ;; Option 3 ((= MyAnswer "Option 4") (/ (+ (* e 2.45) 75) 1.24)) ;; Option 4 )) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2)) (set_tile "res2" "Text text text")) ) ; end cond ) ) ) ) (start_dialog) ) ) (*error* nil) (princ) ); end defun Thanks Quote Link to comment Share on other sites More sharing options...
rlx Posted Saturday at 10:05 PM Share Posted Saturday at 10:05 PM (edited) I think Steven and Bigal have given some excellent and learnfull advise so far , but , your code is like getting too near to a black hole and is getting spaghettified. And believe me , I'm an expert on black holes , just ask my wife ... Anyways , maybe just taking count calcula out of the vl-princ-to-string environment could make it a bit more readable? I'm not sure if I do the math correct because I see no real difference between the handling of (<= e 250) , (and (> e 250) (<= e 1000)) & (and (> e 250) (<= e 1000)) But I'll leave that up to you code below is just meant as advise to supplement the ones posted before , not to compete. And believe me , you don't want to compete with me because if I end up in a life threatening situation , I always carry a picture of my mother-in-law in my wallet! Yeah I know , that's cruel , even by my standards , but as a last resort.... and trust me , once seen , it cannot be unseen. (defun c:test (/ *error* dch dcl des area e my-pop-list pop-index) (defun *error* (m) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch)) (if (= 'file (type des))(close des))(if (and (= 'str (type dcl))(findfile dcl))(vl-file-delete dcl)) (if (and m (not (wcmatch (strcase m t) "*break,*cancel*,*exit*")))(princ (strcat "\nError: " m)))(princ)) ;;; action popup_list returns index number as a string so use (nth (atoi pop-index) my-pop ;;; also no harm in using 'area' in both lisp & dcl instead of just a , just a better read , that's all (setq pop-index "0" my-pop-list '("Option 1" "Option 2" "Option 3" "Option 4")) (cond ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w"))) (princ "\nUnable to open DCL for writing.")) ((progn (foreach str '("eb_10 :edit_box {edit_width=10;}" "bt_10 :button {fixed_width=true;width=10;}" "peacost :dialog {label=\"Mhy3sx Nov'24\"; spacer;" " :row {:eb_10 {key=\"eb_area\";label=\"Area\";}:eb_10 {key=\"res1\";label=\"Calc:\";}}" " :eb_10 {key=\"res2\";label=\"Text\";}spacer;:popup_list {key=\"pop_1\";value=\"0\";}" " spacer; :concatenation {alignment=centered;"":bt_10 {key=\"cal\";label=\"Calc\";}ok_only;}}") (write-line str des) ) (setq des (close des) dch (load_dialog dcl))(<= dch 0) ) (princ "\nUnable to load DCL file.") ) ((not (new_dialog "peacost" dch)) (princ "\nUnable to display 'peacost' dialog.")) (t ;;; lock & load the dialog (set_tile "dcl" "Any name") ;;; no harm using area instead of a (action_tile "eb_area" "(setq area $value)") (start_list "pop_1")(mapcar 'add_list my-pop-list)(end_list) (action_tile "pop_1" "(setq pop-index $value)") (action_tile "cal" "(Do_The_Calculation)") (start_dialog) ) ) (*error* nil) (princ) ) (defun Do_The_Calculation ( / calc) ;;; use (calc '(2.50 75)) (defun calc (x) (/ (+ (* (car x) (cadr x)) 1.24))) (set_tile "res1" "") (set_tile "res2" "") ;;; do the t1 math (if (or (not area) (= "" area) (not (setq e (distof area)))) (progn (alert "Please first enter correct value for area")(mode_tile "eb_area" 2)) (setq t1 (calc (nth (atoi pop-index) (list '(2.50 75) '(2.75 85) '(285 95) '(2.45 75)))))) ;;; do the t2 math (setq t2 (nth (atoi pop-index) (list 322.58 354.84 384 400))) ;;; looking at code formulas for all value's for e are handled the same? (mode_tile "eb_area" 2)(set_tile "res1" (rtos (if (> t1 t2) t2 t1) 2 2))(set_tile "res2" "text text text") ) Edited Saturday at 11:01 PM by rlx 1 Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted Sunday at 12:11 AM Author Share Posted Sunday at 12:11 AM Thanks rlx. I get the idea. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted Sunday at 04:11 AM Share Posted Sunday at 04:11 AM (edited) I am still confused, is this what you want ? The code returns the buttons selected, then you can use that in a cond, with your formula, you can add more or less OPTIONX and T1 T2 T3 etc. (defun test ( / ) (if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp")) (if (= ah:but nil)(setq ah:but 1)) (if (= ah:but2 nil)(setq ah:but2 1)) (setq lst1 (list "Select 1st option " "Option 1" "Option 2" "Option 3" "Option 4")) (setq lst2 (list "Select 2nd option " "T1 " "T2")) (ah:buttscol ah:but ah:but2 "Please select " lst1 lst2) (princ (setq ans1 (nth ah:2col lst1))) (princ (setq ans2 (nth ah:2col2 lst2))) (princ) ) (test) Result Ans1 "Option 3" Ans2 "T2" Edited Sunday at 04:14 AM by BIGAL Quote Link to comment Share on other sites More sharing options...
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.