Steven P Posted March 27 Posted March 27 Just by way of example from comments above and before, have a look through this one I've written the DCL file using the write-line as shown above. In the DCL I find it handy to specify the temporary file name, otherwise it might be that each time the DCL runs it might leave the DCL file in the temporary files folder - see below I'll also write each element out in full - it might seam time saving to use a short hand (like your : ed ) but when it comes to debugging or someone else looking at the code, far easier than scrolling up and down Also for that broken the DCL definition down with blank lines in between rows and columns I'll put the OK button as a button rather than OK-Cancel and then you can assign a function to that if you want Final thing I do is to put any functions outside of the action-tiles section, these can be normal LISP, the DCL and the LISP can be tested independently. For the function, I renamed 'a' that was in your lambda - you have a tile called 'a' so this is to avoid confusion. The formula is basically the same whether you pressed 1:1000 or 1:5000 I think so a slight change there to set the values accordingly. You'll need to check that I have the calculations correct, not sure if they were working quite right (defun c:test ( / *error* dch dcl des len wid ) (defun calc ( s / ) (set_tile "res1" "") (set_tile "res2" "") (set_tile "res3" "") (set_tile "res4" "") (setq l 0.0 MyArea 0.0 i 0 ) (while (< i (sslength s)) (progn (setq e (ssname s i) l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) MyArea (+ MyArea (vlax-curve-getarea e)) ) ; end setq ) ; end progn (if (= (get_tile "radio_button02") 1) (progn (setq t3 (* MyArea 0.07)) ; option 1 (default) (setq MyExpt 1) ) (progn (setq t3 (* MyArea 0.10)) ; option 2 (user selected this) (setq MyExpt 5) ) ) (setq t1 ( / (* (- (expt (+ (sqrt MyArea) MyExpt) 2) MyArea) l 0.25) (sqrt MyArea)) ) (setq t5 (- t1 MyArea) ) (setq t6 (- t3 MyArea) ) (setq t7 (- t1 MyArea) ) (setq t8 (- t3 MyArea) ) (mode_tile "a" 2) (set_tile "a" (rtos MyArea 2 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") (setq i (+ i 1)) ) ; end while (princ) ) ; end defun ;;;List of layers (setq LayerList '("Layer1" "Layer2")) ; List of layers (prompt "\n Select a closed polyline") (setq s (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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Start DCL (setq fo (open (setq fname (vl-filename-mktemp "Calcdcl" (getvar "TEMPPREFIX") ".dcl")) "w")) ;;Name the dcl file, reduces temporary files a lot ;;Header (write-line "Calcdcl : dialog {" fo) (write-line " key = \"Calculations\";" fo) (write-line " label = \"Enter the details: \";" fo) (write-line " spacer;" fo) ;;Data Entry (write-line " :boxed_column { width = 25; label = \"Select the scale\"; height = 1.0;" fo) (write-line " : radio_button { height = 1.0; width = 20; is_tab_stop = true; key = \"radio_button01\"; value = 1; label = \"1. 1:1000\"; }" fo) (write-line " : radio_button { height = 1.0; width = 20; is_tab_stop = true; key = \"radio_button02\"; label = \"1. 1:5000\"; }" fo) (write-line " }" fo) ; end boxed column ;;Results (write-line " :boxed_column { width = 25; label = \"Results\"; height = 1.0;" fo) (write-line " :row {alignment = top;" fo) (write-line " :edit_box { key = \"a\"; label = \"Polyline Area:\"; alignment = left; width = 20; edit_width = 10; fixed_width = true; is_enabled = false; }" fo) (write-line " :edit_box { key = \"res1\"; label = \"Calculate An:\"; alignment = left; width = 20; edit_width = 10; fixed_width = true; is_enabled = false; }" fo) (write-line " }" fo) ; end row (write-line " :row {alignment = top;" fo) (write-line " :edit_box { key = \"res2\"; label = \"Area Min:\"; alignment = left; width = 20; edit_width = 10; fixed_width = true; is_enabled = false; }" fo) (write-line " :edit_box { key = \"res3\"; label = \"Area Max:\"; alignment = left; width = 20; edit_width = 10; fixed_width = true; is_enabled = false; }" fo) (write-line " }" fo) ; end row (write-line " :row {alignment = top;" fo) (write-line " :edit_box { key = \"res4\"; label = \"Polyline Area:\"; alignment = left; width = 40; edit_width = 25; fixed_width = true; is_enabled = false; }" fo) (write-line " }" fo) ; end row (write-line " }" fo) ; end boxed column ;;Buttons (write-line " :column { width = 20;" fo) (write-line " :row {alignment = top;" fo) (write-line " : button { key = \"cal\"; label = \"Calc\"; is_default = true; is_cancel = false; fixed_width = true; width = 10; }" fo) (write-line " : button { key = \"OK\"; label = \"OK\"; is_default = true; is_cancel = true; fixed_width = true; width = 10; }" fo) (write-line " : button { key = \"Cancel\"; label = \"Cancel\"; is_cancel = true; fixed_width = true; width = 10; }" fo) (write-line " }" fo) ; end row (write-line " }" fo) ; end column (write-line "}" fo) ; end dialog (close fo) (setq dcl_id (load_dialog fname)) (if (not (new_dialog "Calcdcl" dcl_id)) (exit) ) ;;End DCL definition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;DCL Controls ;;Set up initial tile data ;;Action Tiles (action_tile "a" "(setq a $value)") ;;Buttons (action_tile "cal" "(calc s)") (action_tile "OK" "(done_dialog 1)") (action_tile "Cancel" "(done_dialog 1)") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Run DCL (start_dialog) (unload_dialog dcl_id) (vl-file-delete fname) ;;End of DCL Definition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ) ; end progn ) ; end if (princ) ; exit quietly ) Quote
Jonathan Handojo Posted March 28 Posted March 28 @Steven P Tested it, didn't seem like any scaling calculations were applied. The values did go in, but the values were the same regardless of which option is selected. Quote
Steven P Posted March 28 Posted March 28 Yes, I think I got the calculations part wrong - I'll have a look later and update it 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.