Happy Hobbit Posted March 6, 2016 Posted March 6, 2016 (edited) I have created a lisp that increments attributes which has a remembered variable (getenv "LISPS\\attfusenuminc") in the initget/cond/getkword routine. It works but somehow doesn't seem right. The requirement is for "Specify" to be the default option, but with the choice of "Resume" to restart the numbering from were I left off. Does anyone know a better way? (defun c:test (/ option tmp) (if (getenv "LISPS\\attfusenuminc") (Setq tmp (getenv "LISPS\\attfusenuminc")) (Setq tmp "1") ) (initget (strcat "Specify Resume " tmp)) (setq option (cond ((getkword (strcat "\nFuse Start Number? [specify/Resume ("tmp")] : "))) ("Specify"))) (cond ((eq option "Specify") (princ "\nSpecify Selected")) ((eq option "Resume") (princ "\nResume Selected")) ) (princ) ) It doesn't add a 'dot' to the default option, although it does default to "Specify". I've only included the relevant part of the lisp for clarity, the rest of the attribute increment lisp works well. Edited March 6, 2016 by Happy Hobbit typo Quote
Stefan BMR Posted March 6, 2016 Posted March 6, 2016 Hi Hobbit I think you can simplify your lisp. As it is, it takes two steps to set the Start Number. Please take a look at this code. You can set the number to a new value or press enter to resume. (defun c:test (/ start_number tmp) (or (Setq tmp (getenv "LISPS\\attfusenuminc")) (Setq tmp "1") ) (initget 6) (setq start_number (cond ((getint (strcat "\nFuse Start Number <" tmp ">: "))) (tmp) ) ) ;(setenv "LISPS\\attfusenuminc" start_number) (princ start_number) (princ) ) Quote
Lee Mac Posted March 6, 2016 Posted March 6, 2016 I would echo Stefan's comments, but would write the code slightly differently: (defun c:test ( / num tmp ) (if (setq num (getenv "LISPS\\attfusenuminc")) (setq num (atoi num)) (setq num 1) ) (initget 6) (if (setq tmp (getint (strcat "\nFuse start number <" (itoa num) ">: "))) (setq num tmp) ) (princ num) (princ) ) This way, fuse number variable will always hold an integer value. Quote
Happy Hobbit Posted March 6, 2016 Author Posted March 6, 2016 Thanks you both for taking the time to put me right. I was too blinkered getting the cond statement working correctly to consider another way, it's not dissimilar to your 'Prompting with a Default Option' Lee. Quote
Lee Mac Posted March 6, 2016 Posted March 6, 2016 Indeed, there are many ways to accomplish the same result in AutoLISP You're welcome! 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.