TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: b-rye guy on January 08, 2016, 06:51:45 PM

Title: Load function using open DCL
Post by: b-rye guy on January 08, 2016, 06:51:45 PM
I am trying to learn DCL so I started at aftalisp (http://www.afralisp.net/dialog-control-language/tutorials/dialog-boxes-and-autolisp-part-1.php)

I am having trouble understanding where to put the function lookup into the basic dcl dialog box. Meaning, when user clicks "OK" the lookup is executed. Can someone please advise on where  (load "mytestaction.lsp")    should go? I have learned that putting it outside of an action_tile will cause the lookup regardless of my choice in the dialog box, and that putting it inside of the OK action_tile will cause the code to break and not run.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:mytest ()                                     
  2.  
  3.   (setq dcl_id (load_dialog "mytest.dcl"))             
  4.  
  5.   (if (not (new_dialog "mytest" dcl_id))
  6.   (exit)                                               
  7.   )
  8.     "cancel"                                           
  9.     "(done_dialog) (setq userclick nil)"               
  10.   )
  11.     "accept"                                           
  12.     " (done_dialog)(setq userclick T))"
  13.   )
  14.   (start_dialog)                                       
  15.   (unload_dialog dcl_id)                               
  16. )
Title: Re: Load function using open DCL
Post by: efernal on January 08, 2016, 08:18:41 PM
Code - Auto/Visual Lisp: [Select]
  1. ;; not tested...
  2. (defun C:MYTEST (/ DCL_ID STATUS)
  3.   (if (> (setq DCL_ID (load_dialog "mytest.dcl")) 0)
  4.     (if (new_dialog "mytest" DCL_ID)
  5.       (progn (action_tile "cancel" "(done_dialog 0)")
  6.              (action_tile "accept" "(done_dialog 1))")
  7.              (setq STATUS (start_dialog))
  8.              (unload_dialog DCL_ID)
  9.              (cond ((= STATUS 0) (princ "\n-> Cancelled..."))
  10.                    ((= STATUS 1) (C:LOOKUP)) ; assumes lookup is already loaded...
  11.              )
  12.       )
  13.       (princ "\n-> No \"mytest\" dialog in mytest.dcl...")
  14.     )
  15.     (princ "\n-> Error loading dcl file...")
  16.   )
  17.   (princ)
  18. )
  19.  
Title: Re: Load function using open DCL
Post by: b-rye guy on January 08, 2016, 08:53:04 PM
Code - Auto/Visual Lisp: [Select]
  1. ;; not tested...
  2. (defun C:MYTEST (/ DCL_ID STATUS)
  3.   (if (> (setq DCL_ID (load_dialog "mytest.dcl")) 0)
  4.     (if (new_dialog "mytest" DCL_ID)
  5.       (progn (action_tile "cancel" "(done_dialog 0)")
  6.              (action_tile "accept" "(done_dialog 1))")
  7.              (setq STATUS (start_dialog))
  8.              (unload_dialog DCL_ID)
  9.              (cond ((= STATUS 0) (princ "\n-> Cancelled..."))
  10.                    ((= STATUS 1) (C:LOOKUP)) ; assumes lookup is already loaded...
  11.              )
  12.       )
  13.       (princ "\n-> No \"mytest\" dialog in mytest.dcl...")
  14.     )
  15.     (princ "\n-> Error loading dcl file...")
  16.   )
  17.   (princ)
  18. )
  19.  

Awesome!!! thank you very much. The only change would be to remove the extra parentheses in line 6.

If I am understanding what you did here correctly. You set a variable for done dialog instead of flagging it and then told the program to continue based on the input?
Title: Re: Load function using open DCL
Post by: b-rye guy on January 08, 2016, 09:28:05 PM
Code - Auto/Visual Lisp: [Select]
  1.  
  2.             (cond ((= STATUS 0) (princ "\n-> Cancelled..."))
  3.                    ((= STATUS 1) (C:LOOKUP)) ; assumes lookup is already loaded...
  4.             )
  5.  
  6.  

Just to add a bit of clarity to it I would like to add an alert to the Status 1 condition. It looks like doing so actually breaks the code and stops the lookup due to "too many arguments". Why is this? I also tried adding a new condition for status 1 but then I get an error of their being "too many arguments" again.

Code - Auto/Visual Lisp: [Select]
  1.  
  2.              (cond ((= STATUS 0) (alert "Cancelled by user. Nothing happened."))
  3.                    ((= STATUS 1) (C:LOOKUP (alert "LOOKUP COMPLETE!"))) ; assumes lookup is already loaded, confirms lookup with alert message
  4.              )
  5.  
  6.  

Title: Re: Load function using open DCL
Post by: ronjonp on January 08, 2016, 09:49:27 PM
Take your alert out of the (c:lookup)
Code - Auto/Visual Lisp: [Select]
  1. ((= STATUS 1) (C:LOOKUP) (alert "LOOKUP COMPLETE!"))
Title: Re: Load function using open DCL
Post by: b-rye guy on January 08, 2016, 09:54:27 PM
Take your alert out of the (c:lookup)
Code - Auto/Visual Lisp: [Select]
  1. ((= STATUS 1) (C:LOOKUP) (alert "LOOKUP COMPLETE!"))

Thank you!