mhy3sx Posted March 12 Posted March 12 Hi. I start learning how to use dcl files with a lisp . I am trying to write a lisp code to do some calculations with a dcl file. But I have some mistakes. And I want an extra help in this code, if some cells have no data are empty like lend1,widd1,arif1, lend2,widd2,arif2 , for the calculations set the value 0 DCL file foo : dialog { label = "Calculations" ; :column { : boxed_row { label = "Dimansions:"; : row { : edit_box { key = "lena" ; label = "Length:" ; } : edit_box { key = "wida" ; label = "Width:" ; } : spacer { height = 1; } } } : boxed_row { label = "Dimansions1:"; : row { : edit_box { key = "lend1" ; label = "Length1:" ; } : edit_box { key = "widd1" ; label = "Width1:" ; } : edit_box { key = "arif1" ; label = "Arif1:" ; } : spacer { height = 1; } } } : boxed_row { label = "Dimansions2:"; : row { : edit_box { key = "lend2" ; label = "Length2:" ; } : edit_box { key = "widd2" ; label = "Width2:" ; } : edit_box { key = "arif2" ; label = "Arif2:" ; } : spacer { height = 1; } } } : column { : boxed_row { label = "Calculations:"; : edit_box { key ="res1"; label = "Area :"; is_enabled = false; } : edit_box { key ="res2"; label = "Area2 :"; is_enabled = false; } : edit_box { key ="res3"; label = " C :"; is_enabled = false; } : edit_box { key ="res4"; label = " D :"; is_enabled = false; } : button { key = "cal" ; label = "Calculate" ; } : spacer { height = 1; } } } spacer; ok_only; } } Lisp code (defun c:foo (/ dcl_id lena wida lend1 wid1 arif1 lend2 wid2 arif2) (cond ;; open the dcl file ((not (setq dcl_id (load_dialog foo.dcl"))) (alert "DCL File not found. - Aborting.") (exit) ) ((not (new_dialog "foo" dcl_id "(setq txt (get_attr $key \"label\"))(done_dialog 1)") ) (alert "DCL Label not found. - Aborting.") (exit) ) ) (action_tile "lena" "(setq lena $value)") (action_tile "wida" "(setq wida $value)") (action_tile "lend1" "(setq lend1 $value)") (action_tile "widd1" "(setq widd1 $value)") (action_tile "arif1" "(setq arif1 $value)") (action_tile "lend2" "(setq lend2 $value)") (action_tile "widd2" "(setq widd2 $value)") (action_tile "arif2" "(setq arif2 $value)") (action_tile "cal" (vl-prin1-to-string '( (lambda ( / xa ya lxd1 lyd1 lxd2 lyd2) (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (cond ( (or (not lena) (= "" lena)) (alert "Please enter a length value.") (mode_tile "lena" 2) ) ( (or (not wida) (= "" wida)) (alert "Please enter a width value.") (mode_tile "wida" 2) ) ( (not (setq xa (distof lena))) (alert "The length must be numerical.") (mode_tile "lena" 2) ) ( (not (setq ya (distof wida))) (alert "The width must be numerical.") (mode_tile "wida" 2) ) ( (<= xa 0.0) (alert "The length must be greater than zero.") (mode_tile "lena" 2) ) ( (<= ya 0.0) (alert "The width must be greater than zero.") (mode_tile "wida" 2) ) ;--------------------d1--------------------------------- ( (or (not lend1) (= "" lend1)) (alert "Please enter a length value.") (mode_tile "lend1" 2) ) ( (or (not widd1) (= "" widd1)) (alert "Please enter a width value.") (mode_tile "widd1" 2) ) ( (or (not arif1) (= "" arif1)) (alert "Please enter a arif1 value.") (mode_tile "arif1" 2) ) ( (not (setq lxd1 (distof lend1))) (alert "The length must be numerical.") (mode_tile "lend1" 2) ) ( (not (setq lyd1 (distof widd1))) (alert "The width must be numerical.") (mode_tile "widd1" 2) ) ( (<= lxd1 0.0) (alert "The length must be greater than zero.") (mode_tile "lend1" 2) ) ( (<= lyd1 0.0) (alert "The width must be greater than zero.") (mode_tile "widd1" 2) ) ;--------------------d2--------------------------------- ( (or (not lend2) (= "" lend2)) (alert "Please enter a length value.") (mode_tile "lend2" 2) ) ( (or (not widd2) (= "" widd2)) (alert "Please enter a width value.") (mode_tile "widd2" 2) ) ( (or (not arif2) (= "" arif2)) (alert "Please enter a arif2 value.") (mode_tile "arif2" 2) ) ( (not (setq lxd2 (distof lend2))) (alert "The length must be numerical.") (mode_tile "lend2" 2) ) ( (not (setq lyd2 (distof widd2))) (alert "The width must be numerical.") (mode_tile "widd2" 2) ) ( (<= lxd2 0.0) (alert "The length must be greater than zero.") (mode_tile "lend2" 2) ) ( (<= lyd2 0.0) (alert "The width must be greater than zero.") (mode_tile "widd2" 2) ) (setq a (rtos (* xa ya) 2 2)) (setq b1 (rtos (* lxd1 lyd1 arif1) 2 2)) (setq b2 (rtos (* lxd2 lyd2 arif2) 2 2)) (setq b (rtos (+ b1 b2) 2 2)) (setq c (rtos (-a b) 2 2)) (setq d (rtos (/ b a) 2 2)) ((set_tile "res1" a) 2) ((set_tile "res2" b) 2) ((set_tile "res3" c) 2) ((set_tile "res4" d) 2) ) ) ) ) ) (start_dialog) (princ) ) ; end defun Thanks Quote
Tsuky Posted March 12 Posted March 12 Hi, Just to inspire you, a very old code (obsolete since the appearance of QUICKCALC, but still functional) A calculator in two different formats. Or a calculator in standard notation Or a calculator in Polish notation (HP style) stdcal.zip hpcal.zip Quote
Steven P Posted March 12 Posted March 12 So if you want a value of 0 to be used (or any value), in your LISP can you do a (if (= lend1 nil) (setq lend1 0)) type of thing? I'd also be tempted to move 'cal' out of the action tile and into a separate defun, calling it from the action tile as necessary. Might give you an added function that you can call it whenever any value is modified - more dynamic that way - given some initial checks that the values are all acceptable Second thing I'd do is look at making it dynamic, so that the DCL file is created when the LISP is called rather than relying on CAD to find the linked files - can e-mail the LISP to anyone you want, they just run it and a bit easier to maintain. Loads of examples online using file create and write line function of LISP Quote
mhy3sx Posted March 12 Author Posted March 12 Hi Steven P. This is my first Dcl lisp code so I want to keep it simple. I have seen some codes with the dcl file inside the lisp but I can't understand how it works. Is difficult for me to design a form without seen in real time what Is going on. I do know if out there exist any program to draw Dcl except Open Dcl (Is not good program for me ). Can anyone help me to fix this code , to study it and learn step by step how this works ?? Thanks Quote
BIGAL Posted March 13 Posted March 13 (edited) If you want blank items then for numbers use Set_tile and put say "0" in the tile, for strings can use "" as a default, this way at least your formulas should work. I use (if (= val nil)(setq val1 0)) etc, so every tile can have a value. Then use (rtos val1 2 0) for the set_tile. If you look at the multi getvals you can see the default values are set so no need for lots of alerts. I think you just need to set the values if nothing exists, if you make all the variables global then the = nil will be ignored as it has a value when ran again. The dcl edit box is a text string so numbers must be converted using rtos to display, you could check the value is -ve thats a bit tricky the label should say no -ve is easiest. I know 1 way around this if -ve value pop a child dcl and ask for a new value. Another way to force a range of numbers is to use sliders. Multi GETVALS.lsp Edited March 13 by BIGAL Quote
mhy3sx Posted March 13 Author Posted March 13 I did same changes to the code , but is not working. (defun c:foo (/ dcl_id lena wida lend1 wid1 arif1 lend2 wid2 arif2) (setq dcl_id (load_dialog "foo.dcl")) (if (null dcl_id) (progn (alert "DCL File not found. - Aborting.") (exit) ) ) (setq res (new_dialog "foo" dcl_id)) (if (null res) (progn (alert "DCL Label not found. - Aborting.") (exit) ) ) (action_tile "cal" (lambda () ;; Ensure all input values are initialized (if (= (get_tile \"lena\") nil) (set_tile \"lena\" 0)) (if (= (get_tile \"wida\") nil) (set_tile \"wida\" 0)) (if (= (get_tile \"lend1\") nil) (set_tile \"lend1\" 0)) (if (= (get_tile \"lend2\") nil) (set_tile \"lend2\" 0)) (if (= (get_tile \"widd1\") nil) (set_tile \"widd1\" 0)) (if (= (get_tile \"widd2\") nil) (set_tile \"widd2\" 0)) (if (= (get_tile \"arif1\") nil) (set_tile \"arif1\" 0)) (if (= (get_tile \"arif2\") nil) (set_tile \"arif2\" 0)) ;; Retrieve values from dialog controls (setq xa (get_tile \"lena\")) (setq ya (get_tile \"wida\")) (setq lxd1 (get_tile \"lend1\")) (setq lyd1 (get_tile \"widd1\")) (setq arif1 (get_tile \"arif1\")) (setq lxd2 (get_tile \"lend2\")) (setq lyd2 (get_tile \"widd2\")) (setq arif2 (get_tile \"arif2\")) ;; Perform calculations here ;; ... ;; Update result tiles (set_tile \"res1\" \"Calculated Value1\") (set_tile \"res2\" \"Calculated Value2\") (set_tile \"res3\" \"Calculated Value3\") (set_tile \"res4\" \"Calculated Value4\") ) ) (start_dialog) (princ) ) Quote
Lee Mac Posted March 13 Posted March 13 Related thread - https://www.theswamp.org/index.php?topic=59344.0 Quote
mhy3sx Posted March 13 Author Posted March 13 Hi Lee Mac. Yes, is a related thread, but I am trying to update the code. This post is more complicated. Can you help? Thanks Quote
Steven P Posted March 13 Posted March 13 Very quick change to your code above and it appears to do something for me: This one: On 3/12/2024 at 2:17 PM, Steven P said: I'd also be tempted to move 'cal' out of the action tile and into a separate defun, calling it from the action tile as necessary. (sorry, just been reading an unrelated forum and one of the members there will argue about anything that isn't expressly quoted...) So I made a separate function, moved the action tile actions into that and off it goes. Doing something similar you could make action tiles for all the inputs, similar to below, with a check that the minimum data has been entered, change any value and then the results will change dynamically as you do so - no need to press the 'cal' button. You could also set the tile focus to the next tile to complete if the data hasn't been completed. (defun c:foo (/ dcl_id lena wida lend1 wid1 arif1 lend2 wid2 arif2) (defun footest ( / ) (if (= (get_tile "lena") nil) (set_tile "lena" 0)) (if (= (get_tile "wida") nil) (set_tile "wida" 0)) (if (= (get_tile "lend1") nil) (set_tile "lend1" 0)) (if (= (get_tile "lend2") nil) (set_tile "lend2" 0)) (if (= (get_tile "widd1") nil) (set_tile "widd1" 0)) (if (= (get_tile "widd2") nil) (set_tile "widd2" 0)) (if (= (get_tile "arif1") nil) (set_tile "arif1" 0)) (if (= (get_tile "arif2") nil) (set_tile "arif2" 0)) ;; Retrieve values from dialog controls (setq xa (get_tile "lena")) (setq ya (get_tile "wida")) (setq lxd1 (get_tile "lend1")) (setq lyd1 (get_tile "widd1")) (setq arif1 (get_tile "arif1")) (setq lxd2 (get_tile "lend2")) (setq lyd2 (get_tile "widd2")) (setq arif2 (get_tile "arif2")) ;; Update result tiles (set_tile "res1" "Calculated Value1") (set_tile "res2" "Calculated Value2") (set_tile "res3" "Calculated Value3") (set_tile "res4" "Calculated Value4") ) (setq dcl_id (load_dialog "foo.dcl")) (if (null dcl_id) (progn (alert "DCL File not found. - Aborting.") (exit) ) ) (setq res (new_dialog "foo" dcl_id)) (if (null res) (progn (alert "DCL Label not found. - Aborting.") (exit) ) ) (action_tile "cal" "(footest)") (start_dialog) (princ) ) Quote
mhy3sx Posted March 13 Author Posted March 13 Hi Steven P. I add the calculation functions and something going wrong with the code. Can you tell me how to fix it? (defun c:foo (/ dcl_id lena wida lend1 wid1 arif1 lend2 wid2 arif2) (defun footest ( / ) (if (= (get_tile "lena") nil) (set_tile "lena" 0)) (if (= (get_tile "wida") nil) (set_tile "wida" 0)) (if (= (get_tile "lend1") nil) (set_tile "lend1" 0)) (if (= (get_tile "lend2") nil) (set_tile "lend2" 0)) (if (= (get_tile "widd1") nil) (set_tile "widd1" 0)) (if (= (get_tile "widd2") nil) (set_tile "widd2" 0)) (if (= (get_tile "arif1") nil) (set_tile "arif1" 0)) (if (= (get_tile "arif2") nil) (set_tile "arif2" 0)) ;; Retrieve values from dialog controls (setq xa (get_tile "lena")) (setq ya (get_tile "wida")) (setq lxd1 (get_tile "lend1")) (setq lyd1 (get_tile "widd1")) (setq arif1 (get_tile "arif1")) (setq lxd2 (get_tile "lend2")) (setq lyd2 (get_tile "widd2")) (setq arif2 (get_tile "arif2")) (setq a (rtos (* xa ya) 2 2)) (setq b1 (rtos (* lxd1 lyd1 arif1) 2 2)) (setq b2 (rtos (* lxd2 lyd2 arif2) 2 2)) (setq b (rtos (+ b1 b2) 2 2)) (setq c (rtos (-a b) 2 2)) (setq d (rtos (/ b a) 2 2)) ;; Update result tiles (set_tile "res1" a) (set_tile "res2" b) (set_tile "res3" c) (set_tile "res4" d) ) (setq dcl_id (load_dialog "foo.dcl")) (if (null dcl_id) (progn (alert "DCL File not found. - Aborting.") (exit) ) ) (setq res (new_dialog "foo" dcl_id)) (if (null res) (progn (alert "DCL Label not found. - Aborting.") (exit) ) ) (action_tile "cal" "(footest)") (start_dialog) (princ) ) Thanks Quote
Steven P Posted March 13 Posted March 13 I think the inputs are all returned as strings, so for example xa will be something like "2" and not 2. Use (atof... ) or (atoi.... ) (for real or integer) to convert to numbers: (setq a (rtos (* (atof xa) (atof ya) ) 2 2)) Quote
BIGAL Posted March 14 Posted March 14 Steven P has provided a solution for default value does not exist, you could use a list of tile names and use foreach to set the tile value. Rather than multiple IF's. No code just a suggestion. 1 Quote
mhy3sx Posted March 16 Author Posted March 16 Hi, I did some updates in the code, fix some errors. The calculations are not working. I don't know why. I want to add Steven P code to support empty cells because sometimes (for example in dimension2) will have no data. Here is the code (defun c:foo ( / *error* dch dcl des len wid len1 wid1 ar1 len2 wid2 ar2) (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) ) ; end defun 2 (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;" "}" "" "foo : dialog" "{" " spacer;" " key = \"dcl\";" " : boxed_row" " {" " label = \"Dimensions\";" " : row" " {" " : ed" " {" " key = \"len\";" " label = \"Length:\";" " }" " : ed" " {" " key = \"wid\";" " label = \"Width:\";" " }" " }" " }" " : boxed_row" " {" " label = \"Dimensions1\";" " : row" " {" " : ed" " {" " key = \"len1\";" " label = \"Length:\";" " }" " : ed" " {" " key = \"wid1\";" " label = \"Width:\";" " }" " : ed" " {" " key = \"ar1\";" " label = \"a1:\";" " }" " }" " }" " : boxed_row" " {" " label = \"Dimensions2\";" " : row" " {" " : ed" " {" " key = \"len2\";" " label = \"Length:\";" " }" " : ed" " {" " key = \"wid2\";" " label = \"Width:\";" " }" " : ed" " {" " key = \"ar2\";" " label = \"a2:\";" " }" " }" " }" " : boxed_row" " {" " label = \"Calculations\";" " : column" " {" " : ed { key = \"res1\"; label = \"a:\"; is_enabled = false; }" " : ed { key = \"res2\"; label = \"b:\"; is_enabled = false; }" " : ed { key = \"res3\"; label = \"c:\"; is_enabled = false; }" " : ed { key = \"res4\"; label = \"d:\"; is_enabled = false; }" " }" " }" " spacer;" " : row" " {" " : button { key = \"cal\"; label = \"Calculate\";}" " 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 "foo" dch)) (princ "\nUnable to display 'foo' dialog.") ) ( t (set_tile "dcl" "Calculation Box") (action_tile "len" "(setq len $value)") (action_tile "wid" "(setq wid $value)") (action_tile "len1" "(setq len1 $value)") (action_tile "wid1" "(setq wid1 $value)") (action_tile "ar1" "(setq ar1 $value)") (action_tile "len2" "(setq len2 $value)") (action_tile "wid2" "(setq wid2 $value)") (action_tile "ar2" "(setq ar2 $value)") (action_tile "cal" (vl-prin1-to-string '( (lambda ( / x y x1 y1 x2 y2 a1 a2) (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (cond ; dimensions ( (or (not len) (= "" len)) (alert "Please enter a length value.") (mode_tile "len" 2) ) ( (or (not wid) (= "" wid)) (alert "Please enter a width value.") (mode_tile "wid" 2) ) ( (not (setq x (distof len))) (alert "The length must be numerical.") (mode_tile "len" 2) ) ( (not (setq y (distof wid))) (alert "The width must be numerical.") (mode_tile "wid" 2) ) ( (<= x 0.0) (alert "The length must be greater than zero.") (mode_tile "len" 2) ) ( (<= y 0.0) (alert "The width must be greater than zero.") (mode_tile "wid" 2) ) ; dimension 1 ( (or (not len1) (= "" len1)) (alert "Please enter a length value.") (mode_tile "len1" 2) ) ( (or (not wid1) (= "" wid1)) (alert "Please enter a width value.") (mode_tile "wid1" 2) ) ( (or (not ar1) (= "" ar1)) (alert "Please enter a ar1 value.") (mode_tile "ar1" 2) ) ( (not (setq x1 (distof len1))) (alert "The length must be numerical.") (mode_tile "len1" 2) ) ( (not (setq y1 (distof wid1))) (alert "The width must be numerical.") (mode_tile "wid1" 2) ) ( (not (setq a1 (distof ar1))) (alert "The ar1 must be numerical.") (mode_tile "ar1" 2) ) ( (<= x1 0.0) (alert "The length must be greater than zero.") (mode_tile "len1" 2) ) ( (<= y1 0.0) (alert "The width must be greater than zero.") (mode_tile "wid1" 2) ) ( (<= a1 0.0) (alert "The width must be greater than zero.") (mode_tile "ar1" 2) ) ; dimansion 2 ( (or (not len2) (= "" len2)) (alert "Please enter a length value.") (mode_tile "len2" 2) ) ( (or (not wid2) (= "" wid2)) (alert "Please enter a width value.") (mode_tile "wid2" 2) ) ( (or (not ar2) (= "" ar2)) (alert "Please enter a ar2 value.") (mode_tile "ar2") ) ( (not (setq x2 (distof len1))) (alert "The length must be numerical.") (mode_tile "len2" 2) ) ( (not (setq y2 (distof wid2))) (alert "The width must be numerical.") (mode_tile "wid2" 2) ) ( (not (setq a2 (distof ar2))) (alert "The ar2 must be numerical.") (mode_tile "ar1" 2) ) ( (<= x2 0.0) (alert "The length must be greater than zero.") (mode_tile "len2" 2) ) ( (<= y2 0.0) (alert "The width must be greater than zero.") (mode_tile "wid2" 2) ) ( (<= a2 0.0) (alert "The ar2 must be greater than zero.") (mode_tile "ar2" 2) ) (setq a (rtos (* x y) 2 2)) (setq b1 (rtos (* x1 y1 a1) 2 2)) (setq b2 (rtos (* x2 y2 a2) 2 2)) (setq b (rtos (+ b1 b2) 2 2)) (setq c (rtos (-a b) 2 2)) (setq d (rtos (/ b a) 2 2)) (set_tile "res1" (rtos a 2 2)) (set_tile "res2" (rtos b 2 2)) (set_tile "res3" (rtos c 2 2)) (set_tile "res4" (rtos d 2 2)) ) ; end cond 2 ) ; end lambda ) ) ) ; end action_tile "cal" (start_dialog) ) ) ; end cond 1 (*error* nil) (princ) ) ; end defun I have 2 other questions in the image. Can anyone help? Thanks Quote
BIGAL Posted March 17 Posted March 17 You may need to set the width in each row, same with calculate button, I would do a spacer then Ok that will help make the Calculate not as wide. Not tested. Quote
mhy3sx Posted March 17 Author Posted March 17 Hi BIGAL, I try that, but something is not working. Can you fix the code to have it as an example? Thanks Quote
Steven P Posted March 17 Posted March 17 I tend to look at DCL as a grid, above 5 main rows with 3 columns in each row, define the widths and heights of the columns and rows and I I want a blank just put in : {row} . I find this easier the future to modify - look for the blanks and that's where to put things. BigAls also works adding a spacer Quote
mhy3sx Posted March 17 Author Posted March 17 Hi Steven P. The code have a lot of problems and I can not fix them. 1) Didn't export the calculations 2) Didn't support empty cells 3)Is the gaps in the dcl menu. I am learning DCL and I want this as example to understand why is not working. Can any one fix this code? Thanks Quote
Steven P Posted March 17 Posted March 17 Try this: Main thing I did was to move 'cal' into a separate function - just how I prefer to work but it can help with debugging the calculations in many cases. I think it makes the action tiles easier to follow in many cases having less text in there I put a 't' in the 'cal' conds for the calculation part so that all the above have to be false to look at 't' - in this case all the data has been entered and verified There were a couple of typos - hope I have noted the corrections My personal preference I defined the OK button as a button rather than 'OK-Cancel' but that lets me specify its width as a normal button... and it has an associated action tile.. which if you ever want to can have some functions assigned to it doing it this way. Could also change the text maybe "close" or "end" or something I tidied up the dcl code a little to my preferences - combined a few lines together for example the : ed... all as a single line.. and took out some white spaces - just for me. I made the DCL into more of a grid system, 3 columns to a row all with a specified column width - which let me move the top row about as I wanted, and 4 columns in the button row to set the layout as I liked (defun c:foo ( / *error* dch dcl des len wid len1 wid1 ar1 len2 wid2 ar2) (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) ) ; end defun 2 ;;SP MOVED THIS AS A FUNCTION. OFTEN MORE STABLE THAN AS ACTION TILE, EASIER TO DEBUG (defun Footest ( len wid len1 wid1 ar1 len2 wid2 ar2 / x y x1 y1 x2 y2 a b c d a1 a2 b1 b2) ;;Calculations (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (cond ; dimensions ( (or (not len) (= "" len)) (alert "Please enter a length value.") (mode_tile "len" 2) ) ( (or (not wid) (= "" wid)) (alert "Please enter a width value.") (mode_tile "wid" 2) ) ( (not (setq x (distof len))) (alert "The length must be numerical.") (mode_tile "len" 2) ) ( (not (setq y (distof wid))) (alert "The width must be numerical.") (mode_tile "wid" 2) ) ( (<= x 0.0) (alert "The length must be greater than zero.") (mode_tile "len" 2) ) ( (<= y 0.0) (alert "The width must be greater than zero.") (mode_tile "wid" 2) ) ; dimension 1 ( (or (not len1) (= "" len1)) (alert "Please enter a length value.") (mode_tile "len1" 2) ) ( (or (not wid1) (= "" wid1)) (alert "Please enter a width value.") (mode_tile "wid1" 2) ) ( (or (not ar1) (= "" ar1)) (alert "Please enter a ar1 value.") (mode_tile "ar1" 2) ) ( (not (setq x1 (distof len1))) (alert "The length must be numerical.") (mode_tile "len1" 2) ) ( (not (setq y1 (distof wid1))) (alert "The width must be numerical.") (mode_tile "wid1" 2) ) ( (not (setq a1 (distof ar1))) (alert "The ar1 must be numerical.") (mode_tile "ar1" 2) ) ( (<= x1 0.0) (alert "The length must be greater than zero.") (mode_tile "len1" 2) ) ( (<= y1 0.0) (alert "The width must be greater than zero.") (mode_tile "wid1" 2) ) ( (<= a1 0.0) (alert "The width must be greater than zero.") (mode_tile "ar1" 2) ) ; dimension 2 ( (or (not len2) (= "" len2)) (alert "Please enter a length value.") (mode_tile "len2" 2) ) ( (or (not wid2) (= "" wid2)) (alert "Please enter a width value.") (mode_tile "wid2" 2) ) ( (or (not ar2) (= "" ar2)) (alert "Please enter a ar2 value.") (mode_tile "ar2" 2) ;;SP TYPO: Added '2' ) ( (not (setq x2 (distof len1))) (alert "The length must be numerical.") (mode_tile "len2" 2) ) ( (not (setq y2 (distof wid2))) (alert "The width must be numerical.") (mode_tile "wid2" 2) ) ( (not (setq a2 (distof ar2))) (alert "The ar2 must be numerical.") (mode_tile "ar1" 2) ) ( (<= x2 0.0) (alert "The length must be greater than zero.") (mode_tile "len2" 2) ) ( (<= y2 0.0) (alert "The width must be greater than zero.") (mode_tile "wid2" 2) ) ( (<= a2 0.0) (alert "The ar2 must be greater than zero.") (mode_tile "ar2" 2) ) ( t ;;SP ADDED t (setq a (* x y) ) ;;SP REMOVED (rtos (setq b1 (* x1 y1 a1) ) (setq b2 (* x2 y2 a2) ) (setq b (+ b1 b2) ) (setq c (- a b) ) ;;TYPO (-a to be (- a (setq d (/ b a) ) (set_tile "res1" (rtos a 2 2)) (set_tile "res2" (rtos b 2 2)) (set_tile "res3" (rtos c 2 2)) (set_tile "res4" (rtos d 2 2)) ) ; end t ) ; end cond 2 (princ (list len wid len1 wid1 ar1 len2 wid2 ar2)) ) ; 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.") ) ( (progn (foreach str '( "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" "" "foo : dialog { spacer; key = \"dcl\";" " : boxed_row { label = \"Dimensions\";" " : column { width = 22;" " : ed { key = \"len\"; label = \"Length:\"; }" " }" ; end column " : column { width = 22;" " : ed { key = \"wid\"; label = \"Width:\"; }" " }" ; end column " : column { width = 22;" " }" ; end column " }" ; end boxed row " : boxed_row { label = \"Dimensions1\";" " : column { width = 22;" " : ed { key = \"len1\"; label = \"Length:\"; }" " }" ; end column " : column { width = 22;" " : ed { key = \"wid1\"; label = \"Width:\"; }" " }" ; end column " : column { width = 22;" " : ed { key = \"ar1\"; label = \"a1:\"; }" " }" ; end column " }" ; end boxed column " : boxed_row { label = \"Dimensions2\";" " : column { width = 22;" " : ed { key = \"len2\"; label = \"Length:\"; }" " }" ; end column " : column { width = 22;" " : ed { key = \"wid2\"; label = \"Width:\"; }" " }" ; end column " : column { width = 22;" " : ed { key = \"ar2\"; label = \"a2:\"; }" " }" ; end column " }" ; end boxed row " : boxed_row { label = \"Calculations\";" " : column {" " : ed { key = \"res1\"; label = \"a:\"; is_enabled = false; }" " : ed { key = \"res2\"; label = \"b:\"; is_enabled = false; }" " : ed { key = \"res3\"; label = \"c:\"; is_enabled = false; }" " : ed { key = \"res4\"; label = \"d:\"; is_enabled = false; }" " }" ; end column " }" ; end boxed row " spacer;" " : row {" " : column { width = 16;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculate\"; is_default = true;" " is_cancel = false; fixed_width = true; width = 10; }" ;;SP MODIFIED THIS " }" ; end column " : column { width = 17;" " : button { key = \"OK\"; label = \"OK\"; is_default = true;" " is_cancel = true; fixed_width = true; width = 10; }" ;;SP ADDED THIS " }" ; end column " : column { width = 16;" " }" ; end column " }" ; end row "}" ; end dialog ) ;end list (write-line str des) ) ; end foreach (setq des (close des) dch (load_dialog dcl) ) ; end setq (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ( (not (new_dialog "foo" dch)) (princ "\nUnable to display 'foo' dialog.") ) ( t (set_tile "dcl" "Calculation Box") (action_tile "len" "(setq len $value)") (action_tile "wid" "(setq wid $value)") (action_tile "len1" "(setq len1 $value)") (action_tile "wid1" "(setq wid1 $value)") (action_tile "ar1" "(setq ar1 $value)") (action_tile "len2" "(setq len2 $value)") (action_tile "wid2" "(setq wid2 $value)") (action_tile "ar2" "(setq ar2 $value)") (action_tile "cal" "(footest len wid len1 wid1 ar1 len2 wid2 ar2)") (action_tile "OK" "(done_dialog 1)") (start_dialog) ) ) ; end cond 1 (*error* nil) (princ) ) ; end defun Quote
mhy3sx Posted March 17 Author Posted March 17 Hi Steven P, thanks for the code. The only thing is still missing is to support empty cells (to understand the empty cells as 0) I delete this lines to support the 0 ( (<= x 0.0) (alert "The length must be greater than zero.") (mode_tile "len" 2) ) ( (<= y 0.0) (alert "The width must be greater than zero.") (mode_tile "wid" 2) ) ( (<= x1 0.0) (alert "The length must be greater than zero.") (mode_tile "len1" 2) ) ( (<= y1 0.0) (alert "The width must be greater than zero.") (mode_tile "wid1" 2) ) ( (<= a1 0.0) (alert "The width must be greater than zero.") (mode_tile "ar1" 2) ) ( (<= x2 0.0) (alert "The length must be greater than zero.") (mode_tile "len2" 2) ) ( (<= y2 0.0) (alert "The width must be greater than zero.") (mode_tile "wid2" 2) ) ( (<= a2 0.0) (alert "The ar2 must be greater than zero.") (mode_tile "ar2" 2) ) But I don't know how to write it. I try this but not result (if (= (get_tile "len") nil) (set_tile "len" 0)) (if (= (get_tile "wid") nil) (set_tile "wid" 0)) (if (= (get_tile "len1") nil) (set_tile "len1" 0)) (if (= (get_tile "len2") nil) (set_tile "len2" 0)) (if (= (get_tile "wid1") nil) (set_tile "wid1" 0)) (if (= (get_tile "wid2") nil) (set_tile "wid2" 0)) (if (= (get_tile "ar1") nil) (set_tile "ar1" 0)) (if (= (get_tile "ar2") nil) (set_tile "ar2" 0)) Any ideas? Thanks 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.