TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: asami486 on January 21, 2017, 12:25:58 AM

Title: I'd like to change the default value of this lisp.
Post by: asami486 on January 21, 2017, 12:25:58 AM
I'd like to change this lisp.
(Thank you VVA. eco 1.1)
Its default value is "No" (when I just push the SPACE KEY).
But I wanna change the value to "Yes"
(then it'll remove the objects except a boundary created by the lisp)
Title: Re: I'd like to change the default value of this lisp.
Post by: kdub_nz on January 21, 2017, 01:27:34 AM

Try something like this :

Firstly, you need to understand that hitting ENTER or SPACEBAR on a getkword does not return any of the options
... it actually returns NIL

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (initget "Yes No")
  3. (setq result (getkword  "\nDelete objects? [Yes/No] <Yes> : ") )
  4.  
  5. SPACE or RETURN ==>nil
  6. y or Y          ==> "Yes"
  7. n or N          ==> "No"
  8. apples          ==> Invalid option keyword ... try again
  9.  

Then you need to write some code to catch the nil result, or a correct one

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (initget "Yes No")
  3.        (setq keyword (getkword "\nDelete objects? [Yes/No] <Yes> : "))
  4.        (if (or (not keyword) (= keyword "Yes"))
  5.          (alert "Proceed to delete")
  6.        )
  7.  


Once you are sure of your code replace the existing in the source :

Code - Auto/Visual Lisp: [Select]
  1.               (if pl
  2.                 (progn (initget "Yes No")
  3.                        (setq
  4.                          keyword (getkword "\nDelete objects? [Yes/No] <Yes> : ")
  5.                        )
  6.                        (if (or (not keyword) (= keyword "Yes"))
  7.                          (mapcar '(lambda (x)
  8.                                     (if (vlax-write-enabled-p x)
  9.                                       (vla-erase x)
  10.                                     )
  11.                                   )
  12.                                  obj
  13.                          )
  14.                        )
  15.                 )
  16.                 ;; else
  17.                 (princ "\nIt was not possible to construct a contour")
  18.               ) ;_ end of if
  19.  
  20.  
Title: Re: I'd like to change the default value of this lisp.
Post by: Grrr1337 on January 21, 2017, 03:47:10 PM
Check Lee Mac's tutorial about prompting with default option (http://lee-mac.com/promptwithdefault.html).
This is always a huge help when using getkword.
Title: Re: I'd like to change the default value of this lisp.
Post by: JohnK on January 23, 2017, 09:03:02 AM
Check out my version of the "RRB Default Method" (`my version' is just a very small improvement I did while standing on RRB's shoulders).

https://www.theswamp.org/index.php?topic=39042.msg442290#msg442290
Title: Re: I'd like to change the default value of this lisp.
Post by: CAB on January 25, 2017, 07:52:09 AM
More fun.  8)

-----------   keyword examples  -------------
http://www.theswamp.org/index.php?topic=15173.0
http://www.theswamp.org/index.php?topic=6992.0
http://www.theswamp.org/index.php?topic=15173.0
http://www.theswamp.org/index.php?topic=6992.msg93574#msg93574