mhy3sx Posted December 8, 2024 Posted December 8, 2024 Hi I am trying to update an old lisp code But gives me Error: syntax error Can any one help? (defun c:test ( / *error* a olda dch dcl des ENT layerlist s emin1 emax1 emin2 emax2) ;;;List of layers (setq LayerList '("Layer1" "0")) ; List of layers (prompt "\n Select a polyline") (setq ENT (ssget (list (cons 0 "*POLYLINE") (cons 8 (LM:lst->str LayerList ",")) '(-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>") ) ) ; end ssget, list ) ; end setq (setq a (vlax-curve-getarea ENT) ) (if s (progn (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 = 10; edit_width = 10; fixed_width = true; }" "" "anoxsymb : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Option\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. Option1\";" " }" ; radio_button " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. Option2\";" " }" ; radio_button " spacer;" " : row { width = 22;" " : ed { key = \"olda\"; label = \"Area from old drawing (m2):\"; }" " : ed { key = \"a\"; label = \"Area from selected polyline (m2):\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments......................\"; height = 1.0;" " : row {" " : ed { key = \"res1\"; label = \"coments......................: ±\"; is_enabled = false; }" " }" ; end row " : row {" " : ed { key = \"res2\"; label = \"Emin:\"; is_enabled = false; }" " : ed { key = \"res3\"; label = \"Emax:\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments\"; height = 1.0;" " : row {" " : ed { key = \"res4\"; label = \"coments:\"; is_enabled = false; edit_width = 40; }" " }" ; end row " spacer;" " : row {" " : ed { key = \"res5\"; label = \"coments......................: ±\"; is_enabled = false; }" " }" ; end row " : row {" " : ed { key = \"res6\"; label = \"Emin:\"; is_enabled = false; }" " : ed { key = \"res7\"; label = \"Emax:\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments\"; height = 1.0;" " : row {" " : ed { key = \"res8\"; label = \coments:\"; is_enabled = false; edit_width = 40; }" " }" ; end row " }" ; end boxed_column " spacer;" " : row {" " : column { width = 10; }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculation\"; 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 dialog ) (write-line str des) ) (setq des (close des) dch (load_dialog dcl) ) (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ( (not (new_dialog "anoxsymb" dch)) (princ "\nUnable to display 'anoxsymb' dialog.") ) (t (set_tile "dcl" "coments......................") (action_tile "a" "(setq a $value)") (action_tile "cal" (vl-prin1-to-string (quote (progn (set_tile "a" "") (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (set_tile "res5" "") (set_tile "res6" "") (set_tile "res7" "") (set_tile "res8" "") (cond ((= (get_tile "radio_button01") "1") ; 1. Option1 (setq anox (* olda 0.05) efor (* olda 0.02) emin1 (- olda anox) emax1 (+ olda anox) emin2 (- olda efor) emax2 (+ olda efor) ) (mode_tile "a" 2) (set_tile "a" (rtos a 2 2)) (set_tile "res1" (rtos anox 2 2)) (set_tile "res2" (rtos emin1 2 2)) (set_tile "res3" (rtos emax1 2 2)) (set_tile "res4" (cond ((<= emin1 a emax1) "coments...................... 5%.") ((> emin1 a) "coments......................") ((< emax1 a) "coments......................") ) ) (set_tile "res5" (rtos efor 2 2)) (set_tile "res6" (rtos emin2 2 2)) (set_tile "res7" (rtos emax2 2 2)) (set_tile "res8" (cond ((<= emin2 a emax2) "coments......................2%.") ((> emin2 a) "coments......................") ((< emax2 a) "coments......................") ) ) ) ((= (get_tile "radio_button02") "1") ; 2. Option2 (setq anox (* olda 0.10) efor (* olda 0.02) emin1 (- olda anox) emax1 (+ olda anox) emin2 (- olda efor) emax2 (+ olda efor) ) (mode_tile "a" 2) (set_tile "a" (rtos a 2 2)) (set_tile "res1" (rtos anox 2 2)) (set_tile "res2" (rtos emin1 2 2)) (set_tile "res3" (rtos emax1 2 2)) (set_tile "res4" (cond ((<= emin1 a emax1) "coments......................10%.") ((> emin1 a) "coments......................") ((< emax1 a) "coments......................") ) ) (set_tile "res5" (rtos efor 2 2)) (set_tile "res6" (rtos emin2 2 2)) (set_tile "res7" (rtos emax2 2 2)) (set_tile "res8" (cond ((<= emin2 a emax2) "coments...................... 2%.") ((> emin2 a) "coments......................") ((< emax2 a) "coments......................") ) ) ) ) ; end cond ) ) ) ) ) (start_dialog) ) ) (*error* nil) (princ) ) ) ; end defun Error: syntax error Thanks Quote
marko_ribar Posted December 8, 2024 Posted December 8, 2024 (edited) Here, I cleaned your code again... There was small error in DCL which I fixed and added setting "olda" = "a" variable at the beginning of lisp... I don't know what do you do with all this, but I made sure it works... Now rest of fine tunning I leave to you... (defun c:test ( / *error* LM:lst->str a olda dch dcl des ent layerlist s anox efor emin1 emax1 emin2 emax2 ) (defun *error* ( msg ) (if (and (= (quote int) (type dch)) (< 0 dch)) (unload_dialog dch) ) (if (= (quote file) (type des)) (close des) ) (if (and (= (quote 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) ) (defun LM:lst->str ( lst del ) (if (cdr lst) (strcat (car lst) del (LM:lst->str (cdr lst) del)) (car lst) ) ) ;;;List of layers (setq LayerList (list "Layer1" "0")) (prompt "\nPick a closed polyline...") (setq s (ssget "_+.:E:S" (list (cons 0 "*POLYLINE") (cons 8 (LM:lst->str LayerList ",")) '(-4 . "<OR") '(70 . 1) '(70 . 3) '(-4 . "<AND") '(70 . 5) '(75 . 5) '(-4 . "AND>") '(-4 . "<AND") '(70 . 5) '(75 . 6) '(-4 . "AND>") '(70 . 129) '(-4 . "<AND") '(70 . 131) '(75 . 0) '(-4 . "AND>") '(-4 . "<AND") '(70 . 131) '(75 . 5) '(-4 . "AND>") '(-4 . "<AND") '(70 . 133) '(75 . 5) '(-4 . "AND>") '(-4 . "<AND") '(70 . 133) '(75 . 6) '(-4 . "AND>") '(-4 . "OR>") ) ) ) (setq a (vlax-curve-getarea (setq ent (ssname s 0)))) (setq olda a) ;;; Added this line as dialog box won't perform calculation without setting variable "olda" ; mod. by M.R. ;;; (if ent (progn (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 = 10; edit_width = 10; fixed_width = true; }" "" "anoxsymb : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Option\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. Option1\";" " }" ; radio_button " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. Option2\";" " }" ; radio_button " spacer;" " : row { width = 22;" " : ed { key = \"olda\"; label = \"Area from old drawing (m2):\"; }" " : ed { key = \"a\"; label = \"Area from selected polyline (m2):\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments......................\"; height = 1.0;" " : row {" " : ed { key = \"res1\"; label = \"coments......................: ±\"; is_enabled = false; }" " }" ; end row " : row {" " : ed { key = \"res2\"; label = \"Emin:\"; is_enabled = false; }" " : ed { key = \"res3\"; label = \"Emax:\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments\"; height = 1.0;" " : row {" " : ed { key = \"res4\"; label = \"coments:\"; is_enabled = false; edit_width = 40; }" " }" ; end row " spacer;" " : row {" " : ed { key = \"res5\"; label = \"coments......................: ±\"; is_enabled = false; }" " }" ; end row " : row {" " : ed { key = \"res6\"; label = \"Emin:\"; is_enabled = false; }" " : ed { key = \"res7\"; label = \"Emax:\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments\"; height = 1.0;" " : row {" " : ed { key = \"res8\"; label = \"coments:\"; is_enabled = false; edit_width = 40; }" " }" ; end row " }" ; end boxed_column " spacer;" " : row {" " : column { width = 10; }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculation\"; 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 dialog ) (write-line str des) ) (setq des (close des) dch (load_dialog dcl) ) (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ( (not (new_dialog "anoxsymb" dch)) (princ "\nUnable to display 'anoxsymb' dialog.") ) ( t (set_tile "dcl" "coments......................") (action_tile "a" "(setq a $value)") (action_tile "cal" (vl-prin1-to-string (quote (progn (set_tile "a" "") (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (set_tile "res5" "") (set_tile "res6" "") (set_tile "res7" "") (set_tile "res8" "") (cond ( (= (get_tile "radio_button01") "1") ; 1. Option1 (setq anox (* olda 0.05) efor (* olda 0.02) emin1 (- olda anox) emax1 (+ olda anox) emin2 (- olda efor) emax2 (+ olda efor) ) (mode_tile "a" 2) (set_tile "a" (if (= (type a) (quote real)) (rtos a 2 4) (rtos (atof a) 2 4))) (set_tile "res1" (rtos anox 2 2)) (set_tile "res2" (rtos emin1 2 2)) (set_tile "res3" (rtos emax1 2 2)) (set_tile "res4" (cond ( (<= emin1 (if (= (type a) (quote str)) (atof a) a) emax1) "coments...................... 5%." ) ( (> emin1 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ( (< emax1 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ) ) (set_tile "res5" (rtos efor 2 2)) (set_tile "res6" (rtos emin2 2 2)) (set_tile "res7" (rtos emax2 2 2)) (set_tile "res8" (cond ( (<= emin2 (if (= (type a) (quote str)) (atof a) a) emax2) "coments......................2%." ) ( (> emin2 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ( (< emax2 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ) ) ) ( (= (get_tile "radio_button02") "1") ; 2. Option2 (setq anox (* olda 0.10) efor (* olda 0.02) emin1 (- olda anox) emax1 (+ olda anox) emin2 (- olda efor) emax2 (+ olda efor) ) (mode_tile "a" 2) (set_tile "a" (if (= (type a) (quote real)) (rtos a 2 4) (rtos (atof a) 2 4))) (set_tile "res1" (rtos anox 2 2)) (set_tile "res2" (rtos emin1 2 2)) (set_tile "res3" (rtos emax1 2 2)) (set_tile "res4" (cond ( (<= emin1 (if (= (type a) (quote str)) (atof a) a) emax1) "coments......................10%." ) ( (> emin1 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ( (< emax1 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ) ) (set_tile "res5" (rtos efor 2 2)) (set_tile "res6" (rtos emin2 2 2)) (set_tile "res7" (rtos emax2 2 2)) (set_tile "res8" (cond ( (<= emin2 (if (= (type a) (quote str)) (atof a) a) emax2) "coments...................... 2%." ) ( (> emin2 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ( (< emax2 (if (= (type a) (quote str)) (atof a) a)) "coments......................" ) ) ) ) ) ) ) ) ) ) ) (start_dialog) ) ) (*error* nil) ) HTH. Regards, M.R. Edited December 8, 2024 by marko_ribar Quote
rlx Posted December 8, 2024 Posted December 8, 2024 (edited) haha Marko just beat me to it... awell , here's my code anyway but there where many , too many mistakes in OP's code , sloppy... (defun c:test ( / *error* ss a olda dch dcl des ENT layerlist s emin1 emax1 emin2 emax2) ;; List to String - Lee Mac ;; Concatenates each string in a supplied list, separated by a given delimiter ;; lst - [lst] List of strings to concatenate ;; del - [str] Delimiter string to separate each item (defun LM:lst->str ( lst del / str ) (setq str (car lst)) (foreach itm (cdr lst) (setq str (strcat str del itm))) str ) (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) ) ;;;List of layers (setq LayerList '("Layer1" "0")) ; List of layers (prompt "\n Select a polyline") (if (and (setq ss (ssget (list (cons 0 "*POLYLINE") (cons 8 (LM:lst->str LayerList ",")) '(-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>")))) (setq a (vlax-curve-getarea (ssname ss 0))) (setq olda a)) (progn (if (not (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w")))) (alert "Unable to open DCL for writing") (progn (foreach str '( "ed : edit_box { alignment = left; width = 10; edit_width = 10; fixed_width = true; }" "" "anoxsymb : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Option\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. Option1\";" " }" ; radio_button " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. Option2\";" " }" ; radio_button " spacer;" " : row { width = 22;" " : ed { key = \"olda\"; label = \"Area from old drawing (m2):\"; }" " : ed { key = \"a\"; label = \"Area from selected polyline (m2):\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments......................\"; height = 1.0;" " : row {" " : ed { key = \"res1\"; label = \"coments......................: ±\"; is_enabled = false; }" " }" ; end row " : row {" " : ed { key = \"res2\"; label = \"Emin:\"; is_enabled = false; }" " : ed { key = \"res3\"; label = \"Emax:\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments\"; height = 1.0;" " : row {" " : ed { key = \"res4\"; label = \"coments:\"; is_enabled = false; edit_width = 40; }" " }" ; end row " spacer;" " : row {" " : ed { key = \"res5\"; label = \"coments......................: ±\"; is_enabled = false; }" " }" ; end row " : row {" " : ed { key = \"res6\"; label = \"Emin:\"; is_enabled = false; }" " : ed { key = \"res7\"; label = \"Emax:\"; is_enabled = false; }" " }" ; end row " }" ; end boxed_column " : boxed_column { label = \"coments\"; height = 1.0;" " : row {" " : ed {key = \"res8\"; label = \"Comments\"; is_enabled = false; edit_width = 40; }" " }" ; end row " }" ; end boxed_column " spacer;" " : row {" " : column { width = 10; }" ; end column " : column { width = 17;" " : button {key=\"cal\";label=\"Calculation\";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 dialog ) (write-line str des) ) (setq des (close des) dch (load_dialog dcl)) ) ) (cond ((<= dch 0) (princ "\nUnable to load DCL file.")) ((not (new_dialog "anoxsymb" dch)) (princ "\nUnable to display 'anoxsymb' dialog.")) (t (set_tile "dcl" "coments......................") (action_tile "OK" "(done_dialog)") (action_tile "a" "(setq a $value)") (action_tile "cal" "(CountCalcula)") (start_dialog) ) ) ) ) (setq *error* nil) (princ) ) ; end defun (defun CountCalcula () (set_tile "a" "") (set_tile "res1" "")(set_tile "res2" "")(set_tile "res3" "")(set_tile "res4" "") (set_tile "res5" "")(set_tile "res6" "")(set_tile "res7" "")(set_tile "res8" "") (cond ;;; 1. Option1 ((= (get_tile "radio_button01") "1") (setq anox (* olda 0.05) efor (* olda 0.02) emin1 (- olda anox) emax1 (+ olda anox) emin2 (- olda efor) emax2 (+ olda efor)) (mode_tile "a" 2) (set_tile "a" (rtos a 2 2)) (set_tile "res1" (rtos anox 2 2)) (set_tile "res2" (rtos emin1 2 2)) (set_tile "res3" (rtos emax1 2 2)) (set_tile "res4" (cond ((<= emin1 a emax1) "coments...................... 5%.") ((> emin1 a) "coments......................") ((< emax1 a) "coments......................") ) ) (set_tile "res5" (rtos efor 2 2)) (set_tile "res6" (rtos emin2 2 2)) (set_tile "res7" (rtos emax2 2 2)) (set_tile "res8" (cond ((<= emin2 a emax2) "coments......................2%.") ((> emin2 a) "coments......................") ((< emax2 a) "coments......................") ) ) ) ;;; 2. Option2 ((= (get_tile "radio_button02") "1") (setq anox (* olda 0.10) efor (* olda 0.02) emin1 (- olda anox) emax1 (+ olda anox) emin2 (- olda efor) emax2 (+ olda efor)) (mode_tile "a" 2) (set_tile "a" (rtos a 2 2)) (set_tile "res1" (rtos anox 2 2)) (set_tile "res2" (rtos emin1 2 2)) (set_tile "res3" (rtos emax1 2 2)) (set_tile "res4" (cond ((<= emin1 a emax1) "coments......................10%.") ((> emin1 a) "coments......................") ((< emax1 a) "coments......................") ) ) (set_tile "res5" (rtos efor 2 2)) (set_tile "res6" (rtos emin2 2 2)) (set_tile "res7" (rtos emax2 2 2)) (set_tile "res8" (cond ((<= emin2 a emax2) "coments...................... 2%.") ((> emin2 a) "coments......................") ((< emax2 a) "coments......................") ) ) ) ) ; end cond ) Edited December 8, 2024 by rlx Quote
mhy3sx Posted December 8, 2024 Author Posted December 8, 2024 Hi , Thanks for the help. rlx I test your code but the calculations is wrong in this part anox (* olda 0.05) is correct but in the result give me this anox (* a 0.05) Can you fix it? Thanks Quote
mhy3sx Posted December 8, 2024 Author Posted December 8, 2024 I find it . I add (defun CountCalcula () (cond ((not (setq olda (distof (get_tile "olda")))) (setq len 0.0) ) ) ;.............. rest of the code Quote
mhy3sx Posted December 8, 2024 Author Posted December 8, 2024 I want to ask something else. I make this box biger. " : ed {key = \"res8\"; label = \"Comment:\"; is_enabled = false; edit_width = 60; height = 4.0; }" I have a big comment to insert ((> emin1 a) "coments..................................................................................................................") ((< emax1 a) "coments..................................................................................................................") ((> emin2 a) "coments...................................................................................................................") ((< emax2 a) "coments...................................................................................................................") Is any way to warp the insert comment in the box? Thanks Quote
rlx Posted December 8, 2024 Posted December 8, 2024 (edited) maybe create a second pre-defined edit box like you did for "ed : edit_box { alignment = left; width = 10; edit_width = 10; fixed_width = true; }" but now call it "ed100 : edit_box {fixed_width=true;width=100; edit_width=100;}" ps you don't need the alignment part for edit boxes , as far as I know they are always left aligned. Edited December 8, 2024 by rlx Quote
mhy3sx Posted December 8, 2024 Author Posted December 8, 2024 I find this way . I divide the text to tree parts. I don't know if it is any other better way !!! " : boxed_column { label = \"comment\"; height = 1.0;" " : row {" " : ed { key = \"res4_1\"; label = \" \"; is_enabled = false; edit_width = 80;}" " }" ; end row " : row {" " : ed { key = \"res4_2\"; label = \" \"; is_enabled = false; edit_width = 80;}" " }" ; end row " : row {" " : ed { key = \"res4_3\"; label = \" \"; is_enabled = false; edit_width = 80;}" " }" ; end row " }" ; end boxed_column (set_tile "res4_1" (cond ((<= emin1 a emax1) " ....................................................") ((> emin1 a) " ....................................................") ((< emax1 a) " ....................................................") ) ) (set_tile "res4_2" (cond ((<= emin1 a emax1) " ....................................................") ((> emin1 a) " ....................................................") ((< emax1 a) " ....................................................") ) ) (set_tile "res4_3" (cond ((<= emin1 a emax1) " ....................................................") ((> emin1 a) " ....................................................") ((< emax1 a) " ....................................................") ) ) Thanks Quote
rlx Posted December 8, 2024 Posted December 8, 2024 if it works for you it works, some forms of coding can sometimes better and some forms are just ego tripping now its bed time for me , early bird tomorrow (5.30 am) 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.