Jump to content

Initget/Getkword: press any key to do A or Enter to do B


KeithXP

Recommended Posts

Title says it all really. I am trying to allow the user to easily/quickly choose whether to do something by pressing any key (or perhaps the spacebar), or to bypass the option with 'Enter'.

 

I cannot figure out how to do this with getkword or getstring, but I am fairly novice at autolisp and would be grateful for some pointers.

 

thanks

Link to comment
Share on other sites

Since a 'Space' is considered 'Enter' I think the closest you will get is:

 

(initget "A B")
(if (= "A" (getkword "\nChoose [A/B] <B>: "))
 ... Do A ...
 ... Do B ...
)

 

Perhaps have a read of my tutorial on the topic.

 

I suppose you could use a workaround with getstring, but its not the best practice:

 

(if (= "" (getstring t "\nPress Any Key for A, Enter for B: "))
 ... Do B ...
 ... Do A ...
)

Link to comment
Share on other sites

Check this out buddy .:)

 

Option A

(if (not
     (eq (setq ansA (getstring "\n Press any key to go with A :"))
         ""
     )
   )
 (alert " Now you are going with option A ")
 (alert " It is not going with A")
)

Option B

 

(if (eq (setq ansB (getstring "\n Press Enter to go with B :"))
       ""
   )
 (alert " Now you are going with option B ")
 (alert " It is not going with B")
)

Tharwat

Link to comment
Share on other sites

Had not seen Tharwat's post when I chose this solution:

 

 (initget "Set Not")
 (setq ans (cond ( (getkword "\nSet planting area in name tag? [set/do Not set] <Set>: ")) ("Set")))

 (if (= ans "Set")
   (progn
   (command "-vbarun" "SetPlantingArea")(princ)
   )
  )

 

The 'setplantingarea' vba routine does not expect any arguments. The line

(command "-vbarun" "setplantingarea") runs in isolation without returning any error. However, when run as part of the code snippet I get:

 

 

Set planting area in tag? [set/do Not set]
: s

 

Set planting area in tag? [set/do Not set]
:

 

*Invalid selection*

Expects a point or Last

 

*Invalid selection*

Expects a point or Last

Function cancelledSelect area object:

Command: Select destination tag:

 

I have no idea what is generating the 'invalid selection' error! The SetPlantingArea routine works perfectly despite the error on the command line.

Link to comment
Share on other sites

I use a this scenario quite a lot:

(initget "Yes No")
(if (/= "No" (getkword "\nDo It - (Yes/No) <Y>:   "))
   (do_it))

 

 

This way a "Yes" or a nil ( enter ) both return T -David

Link to comment
Share on other sites

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