mhy3sx Posted March 24 Posted March 24 Hi, I write this code to do some calculations. The load without erros , select the polyline , open the dcl menu , selecti option1 or option 2 and when i press the calculation button the dcl menu close and calculate nothing. Can anyone help me to fix this error. (defun c:test ( / *error* dch dcl des len wid ) ;;;List of layers (setq LayerList '("Layer1" "Layer2")) ; List of layers (prompt "\n Select a close polyline") (setq s ; Selection set of closed polylines on layers (ssget (list (cons 0 "*POLYLINE") (cons 8 (LM:lst->str LayerList ",")) '(-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>") ) ) ; end ssget, list ) ; end setq (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 = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Select the scale\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. 1:1000\";" " }" ; radio_button " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. 1:5000\";" " }" ; radio_button " }" ;end boxed_column " : boxed_column { label = \"Results\"; height = 1.0;" " : row" " {" " : ed { key = \"a\"; label = \"Polyline Area:\"; is_enabled = false;}" " : ed { key = \"res1\"; label = \"Calculate An:\"; is_enabled = false; }" " }"; end row " : row" " {" " : ed { key = \"res2\"; label = \"Area min:\"; is_enabled = false;}" " : ed { key = \"res3\"; label = \"Area max:\"; is_enabled = false; }" " }"; end row " : row" " {" " : ed { key = \"res4\"; label = \"Comment :\"; is_enabled = false; }" " }"; end row " }" ;end boxed_column " : row" " {" " : column { width = 10;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculations\"; 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 "test" dch)) (princ "\nUnable to display 'test' dialog.") ) (t (set_tile "dcl" "Calculate An") (action_tile "a" "(setq a $value)") (action_tile "cal" (vl-prin1-to-string '( (lambda ( / x) (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (setq l 0.0 a 0.0 i 0 ) (while (< i (sslength s)) (progn (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) ) a (+ a (vlax-curve-getarea e)) ) ) (setq t3 (* a 0.07)) (setq t4 (* a 0.10)) (cond ((= (get_tile "radio_button01") 1) ; Option 1 scale 1:1000 (setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)) t5 (- t1 a) t6 (- t3 a) t7 (- t1 a) t8 (- t3 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t3) t3 t1) 2 2)) (set_tile "res2" (rtos (if (> t1 t3) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t1 t3) t8 t7) 2 2)) (set_tile "res4" "comment") ) ((= (get_tile "radio_button02") 1) ; Option 2 scale 1:5000 (setq t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)) t5 (- t2 a) t6 (- t4 a) t7 (- t2 a) t8 (- t4 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t2 t4) t4 t2) 2 2)) (set_tile "res2" (rtos (if (> t2 t4) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t2 t4) t8 t7) 2 2)) (set_tile "res4" "comment") ) ) ; end cond ) ) ) ) (start_dialog) ) ) ) (*error* nil) (princ) ) ) ) Thanks Quote
mhy3sx Posted March 24 Author Posted March 24 I update the code but, The load without erros , select the polyline , open the dcl menu , select option1 or option 2 and when I press the calculation button do nothing and cannot close the Dcl dialog. Can anyone help me to fix this error. (defun c:test (/ *error* s dch dcl des) ;; List of layers (setq LayerList '("Layer1" "Layer2")) (prompt "\nSelect a closed polyline") (setq s (ssget (list (cons 0 "*POLYLINE") (cons 8 (LM:lst->str LayerList ",")) '(-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>") ))) (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)))) (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w")) (if (not des) (progn (princ "\nUnable to open DCL for writing.") (return))) (foreach str '( "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Select the scale\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. 1:1000\";}" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. 1:5000\";}" " }" " : boxed_column { label = \"Results\"; height = 1.0;" " : row" " {" " : ed { key = \"a\"; label = \"Polyline Area:\"; is_enabled = false;}" " : ed { key = \"res1\"; label = \"Calculate An:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Area min:\"; is_enabled = false;}" " : ed { key = \"res3\"; label = \"Area max:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res4\"; label = \"Comment :\"; is_enabled = false; }" " }" " }" " : row" " {" " : column { width = 10;}" " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculations\"; 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)) (if (<= dch 0) (progn (princ "\nUnable to load DCL file.") (return))) (if (not (new_dialog "test" dch)) (progn (princ "\nUnable to display 'test' dialog.") (return))) (set_tile "dcl" "Calculate An") (action_tile "a" "(setq a $value)") (action_tile "cal" '(lambda () (setq a 0.0) (setq l 0.0) (setq i 0) (while (< i (sslength s)) (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) a (+ a (vlax-curve-getarea e)) i (1+ i))) (setq t3 (* a 0.07)) (setq t4 (* a 0.10)) (cond ((= (get_tile "radio_button01") 1) ; Option 1 scale 1:1000 (setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)) t5 (- t1 a) t6 (- t3 a) t7 (- t1 a) t8 (- t3 a)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t3) t3 t1) 2 2)) (set_tile "res2" (rtos (if (> t1 t3) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t1 t3) t8 t7) 2 2)) (set_tile "res4" (if (> t1 t3) "comment1" "comment 2"))) ((= (get_tile "radio_button02") 1) ; Option 2 scale 1:5000 (setq t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)) t5 (- t2 a) t6 (- t4 a) t7 (- t2 a) t8 (- t4 a)) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t2 t4) t4 t2) 2 2)) (set_tile "res2" (rtos (if (> t2 t4) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t2 t4) t8 t7) 2 2)) (set_tile "res4" (if (> t2 t4) "comment1" "comment 2"))))) (start_dialog)) (*error* nil) (princ) ) ) Quote
mhupp Posted March 24 Posted March 24 ;;;List of layers (setq LayerList '("Layer1" "Layer2")) ; List of layers (prompt "\n Select a close polyline") (setq s ; Selection set of closed polylines on layers (ssget (list (cons 0 "*POLYLINE") (cons 8 (LM:lst->str LayerList ",")) '(-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>") ) ) ; end ssget, list ) ; end setq (if s (progn can be changed to (prompt "\n Select a close polyline") (if (setq s (ssget '((0 . "*POLYLINE") (8 . "Layer1,Layer2") (-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>")))) (progn You know The calculation part works? I think you need to break it out into another lisp and call it (action_tile "Calc" "(Calc)") Quote
mhy3sx Posted March 25 Author Posted March 25 Hi mhupp. I try this bit i have a Error: syntax error If I understand, you tell me something like ..... (defun c:Calc () (setq a 0.0 l 0.0 i 0) (while (< i (sslength s)) (let ((e (ssname s i))) (setq l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) a (+ a (vlax-curve-getarea e)) i (1+ i)))) (setq t3 (* a 0.07) t4 (* a 0.10)) (cond ((= (atoi (get_tile "radio_button01")) 1) ; Option 1 scale 1:1000 (let ((t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)))) (mode_tile "a" 2) (set_tile "res1" (rtos (min t1 t3) 2 2)) (set_tile "res2" (rtos (- (min t1 t3) a) 2 2)) (set_tile "res3" (rtos (- (min t1 t3) a) 2 2)) (set_tile "res4" (if (> t1 t3) "comment1" "comment 2")))) ((= (atoi (get_tile "radio_button02")) 1) ; Option 2 scale 1:5000 (let ((t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)))) (mode_tile "a" 2) (set_tile "res1" (rtos (min t2 t4) 2 2)) (set_tile "res2" (rtos (- (min t2 t4) a) 2 2)) (set_tile "res3" (rtos (- (min t2 t4) a) 2 2)) (set_tile "res4" (if (> t2 t4) "comment1" "comment 2")))))) (princ) (defun c:test (/ *error* s dch dcl des) (prompt "\n Select a close polyline") (if (setq s (ssget '((0 . "*POLYLINE") (8 . "Layer1,Layer2") (-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>")))) (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)))) (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w")) (if (not des) (progn (princ "\nUnable to open DCL for writing.") (return))) (foreach str '( "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Select the scale\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. 1:1000\";}" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. 1:5000\";}" " }" " : boxed_column { label = \"Results\"; height = 1.0;" " : row" " {" " : ed { key = \"a\"; label = \"Polyline Area:\"; is_enabled = false;}" " : ed { key = \"res1\"; label = \"Calculate An:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Area min:\"; is_enabled = false;}" " : ed { key = \"res3\"; label = \"Area max:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res4\"; label = \"Comment :\"; is_enabled = false; }" " }" " }" " : row" " {" " : column { width = 10;}" " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculations\"; 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)) (if (<= dch 0) (progn (princ "\nUnable to load DCL file.") (return))) (if (not (new_dialog "test" dch)) (progn (princ "\nUnable to display 'test' dialog.") (return))) (set_tile "dcl" "Calculate An") (action_tile "a" "(setq a $value)") (action_tile "Calc" "(c:Calc)") (start_dialog)) (*error* nil) (princ) ) Quote
marko_ribar Posted March 25 Posted March 25 (let ... ) is not a function that belongs to vanilla AutoLISP / VisualLISP... Change it to something that belongs to some adequate function from AutoCAD AutoLISP... 1 Quote
Steven P Posted March 25 Posted March 25 2 hours ago, mhy3sx said: Hi mhupp. I try this bit i have a Error: syntax error If I understand, you tell me something like ..... (defun c:Calc () (setq a 0.0 l 0.0 i 0) (while (< i (sslength s)) (let ((e (ssname s i))) (setq l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) a (+ a (vlax-curve-getarea e)) i (1+ i)))) (setq t3 (* a 0.07) t4 (* a 0.10)) (cond ((= (atoi (get_tile "radio_button01")) 1) ; Option 1 scale 1:1000 (let ((t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)))) (mode_tile "a" 2) (set_tile "res1" (rtos (min t1 t3) 2 2)) (set_tile "res2" (rtos (- (min t1 t3) a) 2 2)) (set_tile "res3" (rtos (- (min t1 t3) a) 2 2)) (set_tile "res4" (if (> t1 t3) "comment1" "comment 2")))) ((= (atoi (get_tile "radio_button02")) 1) ; Option 2 scale 1:5000 (let ((t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)))) (mode_tile "a" 2) (set_tile "res1" (rtos (min t2 t4) 2 2)) (set_tile "res2" (rtos (- (min t2 t4) a) 2 2)) (set_tile "res3" (rtos (- (min t2 t4) a) 2 2)) (set_tile "res4" (if (> t2 t4) "comment1" "comment 2")))))) (princ) (defun c:test (/ *error* s dch dcl des) (prompt "\n Select a close polyline") (if (setq s (ssget '((0 . "*POLYLINE") (8 . "Layer1,Layer2") (-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>")))) (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)))) (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w")) (if (not des) (progn (princ "\nUnable to open DCL for writing.") (return))) (foreach str '( "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Select the scale\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. 1:1000\";}" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. 1:5000\";}" " }" " : boxed_column { label = \"Results\"; height = 1.0;" " : row" " {" " : ed { key = \"a\"; label = \"Polyline Area:\"; is_enabled = false;}" " : ed { key = \"res1\"; label = \"Calculate An:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res2\"; label = \"Area min:\"; is_enabled = false;}" " : ed { key = \"res3\"; label = \"Area max:\"; is_enabled = false; }" " }" " : row" " {" " : ed { key = \"res4\"; label = \"Comment :\"; is_enabled = false; }" " }" " }" " : row" " {" " : column { width = 10;}" " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculations\"; 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)) (if (<= dch 0) (progn (princ "\nUnable to load DCL file.") (return))) (if (not (new_dialog "test" dch)) (progn (princ "\nUnable to display 'test' dialog.") (return))) (set_tile "dcl" "Calculate An") (action_tile "a" "(setq a $value)") (action_tile "Calc" "(c:Calc)") (start_dialog)) (*error* nil) (princ) ) Also look at the example in the other question where I suggested the same for more help. Lines and lines and lines of code make finding errors tricky sometimes Quote
mhy3sx Posted March 25 Author Posted March 25 Hi Steven P. I try but I can not find the error.Can you help? Quote
mhupp Posted March 25 Posted March 25 (edited) Don't have Cad installed (just upgraded to a new PC) to look at the DCL menu but button01 and 02 should drive the calculations? (defun c:test ( / *error* dch dcl des len wid ) (prompt "\n Select a close polyline") (if (setq s (ssget '((0 . "*POLYLINE") (8 . "Layer1,Layer2") (-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>")))) (progn (setq des (open (setq dcl (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" des) (write-line "" des) (write-line "test : dialog { spacer; key = \"dcl\";" des) (write-line " : boxed_column { label = \"Select the scale\"; height = 1.0;" des) (write-line " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" des) (write-line " key = \"radio_button01\"; label = \"1. 1:1000\";" des) (write-line " }" ; radio_button" des) ... (close des) (new_dialog "test" (setq dcl (load_dialog dcl))) (set_tile "dcl" "Calculate An") (action_tile "radio_button01" "(Calc1)") (action_tile "radio_button02" "(Calc2)") (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (start_dialog) (done_dialog) (unload_dialog dcl) (vl-file-delete des) ) ) ) (defun calc1 (/ l a i e t1 t2 t3 t4 t5 t6 t7 t8) ; Option 1 scale 1:1000 (setq l 0.0 a 0.0 i 0) (while (< i (sslength s)) (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) a (+ a (vlax-curve-getarea e)) ) (setq t3 (* a 0.07)) (setq t4 (* a 0.10)) (setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)) t5 (- t1 a) t6 (- t3 a) t7 (- t1 a) t8 (- t3 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t3) t3 t1) 2 2)) (set_tile "res2" (rtos (if (> t1 t3) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t1 t3) t8 t7) 2 2)) (set_tile "res4" (if (> t1 t3) "comment 1" "comment 2")) ) ) (defun calc2 (/ l a i e t1 t2 t3 t4 t5 t6 t7 t8) ; Option 2 scale 1:5000 (setq l 0.0 a 0.0 i 0) (while (< i (sslength s)) (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) a (+ a (vlax-curve-getarea e)) ) (setq t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)) t5 (- t2 a) t6 (- t4 a) t7 (- t2 a) t8 (- t4 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t2 t4) t4 t2) 2 2)) (set_tile "res2" (rtos (if (> t2 t4) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t2 t4) t8 t7) 2 2)) (set_tile "res4" (if (> t2 t4) "comment 1" "comment 2")) ) ) Edited March 25 by mhupp Quote
mhy3sx Posted March 25 Author Posted March 25 Hi mhupp. I am using ZWCAD and for the lisp code notepad++. I find some missing ) and en error in the calculation . I didi the changes but after select the polyline I get a Select objects: nil (defun c:test ( / *error* dch dcl des len wid ) (prompt "\n Select a close polyline") (if (setq s (ssget '((0 . "*POLYLINE") (8 . "Layer1,Layer2") (-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>")))) (progn (setq des (open (setq dcl (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" des) (write-line "" des) (write-line "test : dialog { spacer; key = \"dcl\";" des) (write-line " : boxed_column { label = \"Select the scale\"; height = 1.0;" des) (write-line " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" des) (write-line " key = \"radio_button01\"; label = \"1. 1:1000\";" des) (write-line " }" ; radio_button" des) ... (close des) (new_dialog "test" (setq dcl (load_dialog dcl))) (set_tile "dcl" "Calculate An") (action_tile "radio_button01" "(Calc1)") (action_tile "radio_button02" "(Calc2)") (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (start_dialog) (done_dialog) (unload_dialog dcl) (vl-file-delete des) ) ) ) ) (defun calc1 (/ l a i e t1 t2 t3 t4 t5 t6 t7 t8) ; Option 1 scale 1:1000 (setq l 0.0 a 0.0 i 0) (while (< i (sslength s)) (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) a (+ a (vlax-curve-getarea e)) ) (setq t3 (* a 0.07)) (setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)) t5 (- t1 a) t6 (- t3 a) t7 (- t1 a) t8 (- t3 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t3) t3 t1) 2 2)) (set_tile "res2" (rtos (if (> t1 t3) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t1 t3) t8 t7) 2 2)) (set_tile "res4" (if (> t1 t3) "comment 1" "comment 2")) ) ) (defun calc2 (/ l a i e t1 t2 t3 t4 t5 t6 t7 t8) ; Option 2 scale 1:5000 (setq l 0.0 a 0.0 i 0) (while (< i (sslength s)) (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) a (+ a (vlax-curve-getarea e)) ) (setq t4 (* a 0.10)) (setq t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)) t5 (- t2 a) t6 (- t4 a) t7 (- t2 a) t8 (- t4 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t2 t4) t4 t2) 2 2)) (set_tile "res2" (rtos (if (> t2 t4) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t2 t4) t8 t7) 2 2)) (set_tile "res4" (if (> t2 t4) "comment 1" "comment 2")) ) ) Quote
mhupp Posted March 25 Posted March 25 The ... in the code is for you to fill out the rest of your dcl file sandwiched between (write-line " " des) so its incomplete until you do that. Quote
mhy3sx Posted March 26 Author Posted March 26 Hi mhupp. Why you write the dcl like this? (write-line "test : dialog { spacer; key = \"dcl\";" des) (write-line " : boxed_column { label = \"Select the scale\"; height = 1.0;" des) (write-line " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" des) Quote
Steven P Posted March 26 Posted March 26 'write-line' or 'foreach' method for creating a LISP on the fly both work. I'll also use 'write-line - I find that way can be a bit more versatile Quote
Jonathan Handojo Posted March 26 Posted March 26 (edited) Based off your very first post: (defun c:test ( / *error* a dch dcl des e i l layerlist len s t1 t2 t3 t4 t5 t6 t7 t8 wid) ;; |JH| Variables localised ;;;List of layers (setq LayerList '("Layer1" "Layer2")) ; List of layers (prompt "\n Select a close polyline") (setq s ; Selection set of closed polylines on layers (ssget (list (cons 0 "*POLYLINE") ;(cons 8 (LM:lst->str LayerList ",")) ;; |JH| Temporarily disabled layers for testing '(-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>") ) ) ; end ssget, list ) ; end setq (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 = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Select the scale\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. 1:1000\";" " }" ; radio_button " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. 1:5000\";" " }" ; radio_button " }" ;end boxed_column " : boxed_column { label = \"Results\"; height = 1.0;" " : row" " {" " : ed { key = \"a\"; label = \"Polyline Area:\"; is_enabled = false;}" " : ed { key = \"res1\"; label = \"Calculate An:\"; is_enabled = false; }" " }"; end row " : row" " {" " : ed { key = \"res2\"; label = \"Area min:\"; is_enabled = false;}" " : ed { key = \"res3\"; label = \"Area max:\"; is_enabled = false; }" " }"; end row " : row" " {" " : ed { key = \"res4\"; label = \"Comment :\"; is_enabled = false; }" " }"; end row " }" ;end boxed_column " : row" " {" " : column { width = 10;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculations\"; 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 "test" dch)) (princ "\nUnable to display 'test' dialog.") ) (t (set_tile "dcl" "Calculate An") (action_tile "a" "(setq a $value)") (action_tile "cal" (vl-prin1-to-string (quote ;; |JH| Changed to quote (Not really necessary, but just to have it look neater?) (progn ;; |JH| Changed to progn so that the QUOTE function will not run with any errors. (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (setq l 0.0 a 0.0 i 0 ) (while (< i (sslength s)) (progn (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) ) a (+ a (vlax-curve-getarea e)) i (1+ i) ;; |JH| Line added so as to not get stuck in the while loop. ) ) (setq t3 (* a 0.07)) (setq t4 (* a 0.10)) (cond ((= (get_tile "radio_button01") "1") ; Option 1 scale 1:1000 |JH| - get_tile returns a string, so the "1" needs to be enclosed in a string. (setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)) t5 (- t1 a) t6 (- t3 a) t7 (- t1 a) t8 (- t3 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t3) t3 t1) 2 2)) (set_tile "res2" (rtos (if (> t1 t3) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t1 t3) t8 t7) 2 2)) (set_tile "res4" "comment") ) ((= (get_tile "radio_button02") "1") ; Option 2 scale 1:5000 |JH| - get_tile returns a string, so the "1" needs to be enclosed in a string. (setq t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)) t5 (- t2 a) t6 (- t4 a) t7 (- t2 a) t8 (- t4 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t2 t4) t4 t2) 2 2)) (set_tile "res2" (rtos (if (> t2 t4) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t2 t4) t8 t7) 2 2)) (set_tile "res4" "comment") ) ) ; end cond ) ) ) ) ) (start_dialog) ;; |JH| Moved line to outside the action_tile function. ) ) (*error* nil) (princ) ) ) ) Fyi, this will only get the calculations to show in the dialog box. Whether the calculations themselves are correct or not is to be determined by you. That said, if you're still stuck, don't hesitate to ask again. Edited March 26 by Jonathan Handojo 1 Quote
mhy3sx Posted March 26 Author Posted March 26 Hi Jonathan Handojo. Thanks for the help. I correct the calculation in code. The polyline area is not insert in the cell. Can you fix that? (defun c:test ( / *error* a dch dcl des e i l layerlist len s t1 t2 t3 t4 t5 t6 t7 t8 wid) ;; |JH| Variables localised ;;;List of layers (setq LayerList '("Layer1" "Layer2")) ; List of layers (prompt "\n Select a close polyline") (setq s ; Selection set of closed polylines on layers (ssget (list (cons 0 "*POLYLINE") ;(cons 8 (LM:lst->str LayerList ",")) ;; |JH| Temporarily disabled layers for testing '(-4 . "<OR") '(70 . 1) '(70 . 129) '(-4 . "OR>") ) ) ; end ssget, list ) ; end setq (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 = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"Select the scale\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. 1:1000\";" " }" ; radio_button " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. 1:5000\";" " }" ; radio_button " }" ;end boxed_column " : boxed_column { label = \"Results\"; height = 1.0;" " : row" " {" " : ed { key = \"a\"; label = \"Polyline Area:\"; is_enabled = false;}" " : ed { key = \"res1\"; label = \"Calculate An:\"; is_enabled = false; }" " }"; end row " : row" " {" " : ed { key = \"res2\"; label = \"Area min:\"; is_enabled = false;}" " : ed { key = \"res3\"; label = \"Area max:\"; is_enabled = false; }" " }"; end row " : row" " {" " : ed { key = \"res4\"; label = \"Comment :\"; is_enabled = false; }" " }"; end row " }" ;end boxed_column " : row" " {" " : column { width = 10;" " }" ; end column " : column { width = 17;" " : button { key = \"cal\"; label = \"Calculations\"; 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 "test" dch)) (princ "\nUnable to display 'test' dialog.") ) (t (set_tile "dcl" "Calculate An") (action_tile "a" "(setq a $value)") (action_tile "cal" (vl-prin1-to-string (quote ;; |JH| Changed to quote (Not really necessary, but just to have it look neater?) (progn ;; |JH| Changed to progn so that the QUOTE function will not run with any errors. (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (setq l 0.0 a 0.0 i 0 ) (while (< i (sslength s)) (progn (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) ) a (+ a (vlax-curve-getarea e)) i (1+ i) ;; |JH| Line added so as to not get stuck in the while loop. ) ) (setq t3 (* a 0.07)) (setq t4 (* a 0.10)) (cond ((= (get_tile "radio_button01") "1") ; Option 1 scale 1:1000 |JH| - get_tile returns a string, so the "1" needs to be enclosed in a string. (setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a)) t5 (- t1 a) t6 (- t3 a) t7 (+ t1 a) t8 (+ t3 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t1 t3) t3 t1) 2 2)) (set_tile "res2" (rtos (if (> t1 t3) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t1 t3) t8 t7) 2 2)) (set_tile "res4" "comment") ) ((= (get_tile "radio_button02") "1") ; Option 2 scale 1:5000 |JH| - get_tile returns a string, so the "1" needs to be enclosed in a string. (setq t2 (/ (* (- (expt (+ (sqrt a) 5) 2) a) l 0.25) (sqrt a)) t5 (- t2 a) t6 (- t4 a) t7 (+ t2 a) t8 (+ t4 a) ) (mode_tile "a" 2) (set_tile "res1" (rtos (if (> t2 t4) t4 t2) 2 2)) (set_tile "res2" (rtos (if (> t2 t4) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t2 t4) t8 t7) 2 2)) (set_tile "res4" "comment") ) ) ; end cond ) ) ) ) ) (start_dialog) ;; |JH| Moved line to outside the action_tile function. ) ) (*error* nil) (princ) ) ) ) Thanks Quote
Jonathan Handojo Posted March 26 Posted March 26 (edited) The edit box for your polyline area is stored in the key "a". You haven't set that value yet using set_tile like you did with "res1", "res2", "res3" and "res4". So you need to use (set_tile "a" <your_value>) as well, in addition to the previous 4 that you have set. As for making the edit box bigger, you can easily set the edit_width larger for that specific tile: " : ed { key = \"res4\"; label = \"Comment :\"; is_enabled = false; edit_width = 30; }" ;; <--- Edit width added Edited March 26 by Jonathan Handojo Quote
mhy3sx Posted March 27 Author Posted March 27 Hi Jonathan Handojo. I did the change with the width and all it's ok. I try to (set_tile "a" <your_value>) but I am not giving correct the polyline (quote ;; |JH| Changed to quote (Not really necessary, but just to have it look neater?) (progn ;; |JH| Changed to progn so that the QUOTE function will not run with any errors. (set_tile "a" "") ; <---- add this (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (setq l 0.0 a 0.0 i 0 ) I don't think that is correct !!!! (mode_tile "a" 2) (set_tile "a" "(setq a $value)") (set_tile "res1" (rtos (if (> t1 t3) t3 t1) 2 2)) (set_tile "res2" (rtos (if (> t1 t3) t6 t5) 2 2)) (set_tile "res3" (rtos (if (> t1 t3) t8 t7) 2 2)) (set_tile "res4" "comment") Thanks Quote
Jonathan Handojo Posted March 27 Posted March 27 $value is the value of your action tile. That action is happening as you click the "Calculation" button, so it could not have been $value. Instead, you already have your area calculated and saved in the variable 'a' as a floating number in this point: (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) ) a (+ a (vlax-curve-getarea e)) ;; <---- This value here i (1+ i) ;; |JH| Line added so as to not get stuck in the while loop. ) So it should've been: (set_tile "a" (rtos a 2 2)) But this is before any scaling calculations are applied, which I think (assume, cause I didn't bother with what the numbers actually show) uses your variables t1 to t8. I'll leave that to you to figure out. You've already got most of the code working fine. You just need to ensure the proper numbers are shown. 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.