flowerrobot 发表于 2022-7-6 15:18:17

Initget & getkword

Good morning.
Todays question is about intiget & getkwords
I have a Promt, that either wants a keyword or a distance
 

(setq    mp1 (strcase (getstring "\nENTER WIDTH PLATE, or key for options : ")))(terpri)This is how it is currently set
but as im now just about done debuging it, and this one is buging me, as i want all prompts to be idiot proof. so that i can only select defined letter , or any distance. i only have the knowledge to do either.
this is what i want to happen,(you get the point

(initget 7 "hi")(setq hello ((or (getkword) (getdist)) "\HOW far"))

Lee Mac 发表于 2022-7-6 15:32:20

How about this?
 

(defun c:test (/ hello)   (or    (and (not (initget 6)) (setq hello (getdist "\nHow Far?   ")))          (and (not (initget 1 "hi")) (setq hello (getkword "\How far? "))))   (alert (vl-princ-to-string hello))   (princ))

Lee Mac 发表于 2022-7-6 15:37:47

Obviously you only need this bit:
 

   (or    (and (not (initget 6)) (setq hello (getdist "\nHow Far?   ")))          (and (not (initget 1 "hi")) (setq hello (getkword "\How far? "))))but I thought I'd test it

Lee Mac 发表于 2022-7-6 15:47:14

But I'm sure there is a better way to accomplish this - I don't like the user having to press enter to get to the keyword request.

CarlB 发表于 2022-7-6 15:55:14

Since "getdist" honors keywords, you should be able to use:
 

(initget 7 "hi")(setq hello (getdist "\HOW far "))

flowerrobot 发表于 2022-7-6 16:00:50

o.0 it does too. I must of screw up last night then when i tryed it. (it was close to my bed time)
 
Thank you for the help with my ignorance.

flowerrobot 发表于 2022-7-6 16:09:33

tell me my smart friends
why does this not work?
well it works, but dosnt honour the kword

(initget 7 "100 150 200 250 310")(setq sectype (getint "\nWHAT SIZE IS IT? 100/150/200/250/310 : "))]

CarlB 发表于 2022-7-6 16:14:30

"getint" also honors keywords.but your use of it would allow any positive integer t be input, as well as the keywords which you have as certain text which happen to be numbers.If you want to just allow those numbers to be input then i'd say use "getkword" not "getint".

Lee Mac 发表于 2022-7-6 16:23:15

I must admit, I did not realise, GetInt and GetDist and maybe others honoured keywords -
 
But as Carl rightfully says, in the above example, the list of integers within the initget phrase become keywords, but the use of getint instead of getkword means that every integer is allowed as well as the keywords inside the initget.
页: [1]
查看完整版本: Initget & getkword