乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 86|回复: 5

[编程交流] Initget/Getkword: press any k

[复制链接]

6

主题

11

帖子

5

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 09:16:57 | 显示全部楼层 |阅读模式
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
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 09:34:40 | 显示全部楼层
Since a 'Space' is considered 'Enter' I think the closest you will get is:
 
  1. (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:
 
  1. (if (= "" (getstring t "\nPress Any Key for A, Enter for B: ")) ... Do B ... ... Do A ...)
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 09:50:16 | 显示全部楼层
Check this out buddy .
 
Option A
  1. (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
 
  1. (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
回复

使用道具 举报

6

主题

11

帖子

5

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 10:02:31 | 显示全部楼层
Had not seen Tharwat's post when I chose this solution:
 
  1. (initget "Set Not") (setq ans (cond ( (getkword "\nSet planting area in name tag? [set/do Not 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.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 10:11:22 | 显示全部楼层
Why not nil = A no matter what else make it "B"
 
 
(setq ans (getstring))
(if (= ans nil)(setq ans "A")(setq ans "B"))
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 10:18:16 | 显示全部楼层
I use a this scenario quite a lot:
  1. (initget "Yes No")(if (/= "No" (getkword "\nDo It - (Yes/No) :   "))   (do_it))
 
 
This way a "Yes" or a nil ( enter ) both return T  -David
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-7 02:52 , Processed in 0.475987 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表