Jump to content

initget/cond/getkword routine with a variable


Recommended Posts

Posted (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.

Fuse Start Number.jpg

Edited by Happy Hobbit
typo
Posted

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)
)

Posted

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.

Posted

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.

Posted

Indeed, there are many ways to accomplish the same result in AutoLISP :thumbsup:

 

You're welcome!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...