乐筑天下

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

[编程交流] 如何在ty之后强制进入

[复制链接]
CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 15:25:49 | 显示全部楼层
好的,这是我的一键例行程序,比如GetKword。
我让它有点通用。
  1. ;;  GetKeyPress.lsp
  2. ;;  CAB  version 1.0  03/26/09
  3. ;;  Get one key press from user similar to GetKword
  4. ;;  keys = list of key char & return value  '(("Y" "Yes")("N" "No"))
  5. ;;  def = result if ENTER is pressed  nil or "Yes" or "No" etc
  6. ;;        if nil then Enter is dissallowed
  7. ;;  msg = the prompt nil = "Press a key"
  8. ;;  emsg = the error message nil = "Incorrect keypress."
  9. (defun GetKeyPress (keys def msg emsg / input result)
  10. (or msg (setq msg "Press a key"))
  11. (or emsg (setq emsg "Incorrect keypress."))
  12. (princ (strcat "\n" msg))
  13. (while (null result)
  14.    (and (= (car (setq input (grread))) 2) ; keyboard entry
  15.         (< 31 (setq input (cadr input)) 255) ; a key was pressed
  16.    )
  17.    (cond
  18.      ((listp input)) ; not a keypress
  19.      ((setq result (assoc (strcase (chr input)) keys))
  20.       (setq result (cadr result))
  21.      )
  22.      ((and (= input 13) def)
  23.       (setq result def)
  24.      )
  25.      ((princ (strcat "\n" emsg "\n" msg)))
  26.    )
  27. )
  28. result
  29. )

 
  1. (defun c:test(/ ans)
  2. (setq ans (GetKeyPress
  3.              '(("Y" "Yes")("N" "No"))  ; keys allowed, not case sensitive, & return value
  4.              "Yes" ; default when ENTER is pressed
  5.              "Do you need an extra leader? (Y/N) [Yes]:" ; message prompt
  6.              nil ; use default error message
  7.              ))
  8. (princ ans)
  9. (princ)
  10. )
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:28:07 | 显示全部楼层
啊。。。很漂亮的出租车,没想到格雷德
回复

使用道具 举报

4

主题

13

帖子

9

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 15:32:42 | 显示全部楼层
谢谢你,出租车!!那么,在代码中如何调用该函数呢?我现在很困惑
 
这是我的完整代码:
 
(定义c:bom()
(命令“-osnap”“”)
(命令“ortho”“Off”)
 
;-- 获取插入BOM表块所需的参数
(setq ip(getpoint“\n插入点:”)
(setq int1(getint“\n项目编号:”))
(setq st1(getstring“\n左文本:”))
(setq st2(getstring“\n右文本:”))
 
;-- 将图层设置为文字
(命令“-layer”“set”“TEXT”“”)
 
;--插入具有给定参数的块
(命令“_insert”“bom”ip”“”“int1 st1 st2)
(setq ldr2“Y”)
(同时(=ldr2“Y”)
 
;-- 获取引导点并绘制它
(setq pt1(获取点ip“\n连接到:”)
(setq pt2(极性ip(角度ip pt1)0.1625))--这是BOM表圆上的pt
(命令“_line”pt2 pt1”)
 
我想我必须在这里调用你的函数,但我现在不知道如何调用它
;-- 请另一位领导(原始代码)
(initget“Y”)
(setq ldr2(getkword“\N您需要额外的领导者吗?(是/否):”)
 
)
 
(命令“-layer“T”0“ON“0”set“0”)
(普林斯)
)
 
 
我会感谢你的帮助。
 
非常感谢。
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 15:34:59 | 显示全部楼层
试试这个:
  1. (defun c:bom ()
  2. (command "-osnap" "")
  3. (command "ortho" "Off")
  4. ;;-- Get the parameter reqd to insert the BOM block
  5. (setq ip (getpoint "\nInsertion Point: "))
  6. (setq int1 (getint "\nItem Number: "))
  7. (setq st1 (getstring "\nLeft Text: "))
  8. (setq st2 (getstring "\nRight Text: "))
  9. ;;-- Set layer to TEXT
  10. (command "-layer" "set" "TEXT" "")
  11. ;;--Insert the block with the given params
  12. (command "_insert" "bom" ip "" "" "" int1 st1 st2)
  13. (setq ldr2 "Y")
  14. (while (= ldr2 "Y")
  15.    ;;-- Get the leader point & draw it
  16.    (setq pt1 (getpoint ip "\nConnect to: "))
  17.    (setq pt2 (polar ip (angle ip pt1) 0.1625))
  18.    ;;--This is the pt on the BOM circle
  19.    (command "_line" pt2 pt1 "")
  20.    ;;-- Ask for another leader (original code)
  21.    (setq ldr2 (GetKeyPress
  22.                 '(("Y" "Yes") ("N" "No")); keys allowed, not case sensitive, & return value
  23.                 "Yes"                  ; default when ENTER is pressed
  24.                 "Do you need an extra leader? (Y/N) [Yes]:" ; message prompt
  25.                 nil                    ; use default error message
  26.               )
  27.    )
  28. )
  29. (command "-layer" "T" "0" "ON" "0" "set" "0" "")
  30. (princ)
  31. )
  32. ;;  GetKeyPress.lsp
  33. ;;  CAB  version 1.0  03/26/09
  34. ;;  Get one key press from user similar to GetKword
  35. ;;  keys = list of key char & return value  '(("Y" "Yes")("N" "No"))
  36. ;;  def = result if ENTER is pressed  nil or "Yes" or "No" etc
  37. ;;        if nil then Enter is dissallowed
  38. ;;  msg = the prompt nil = "Press a key"
  39. ;;  emsg = the error message nil = "Incorrect keypress."
  40. (defun GetKeyPress (keys def msg emsg / input result)
  41. (or msg (setq msg "Press a key"))
  42. (or emsg (setq emsg "Incorrect keypress."))
  43. (princ (strcat "\n" msg))
  44. (while (null result)
  45.    (and (= (car (setq input (grread))) 2) ; keyboard entry
  46.         (< 31 (setq input (cadr input)) 255) ; a key was pressed
  47.    )
  48.    (cond
  49.      ((listp input))                   ; not a keypress
  50.      ((setq result (assoc (strcase (chr input)) keys))
  51.       (setq result (cadr result))
  52.      )
  53.      ((and (= input 13) def)
  54.       (setq result def)
  55.      )
  56.      ((princ (strcat "\n" emsg "\n" msg)))
  57.    )
  58. )
  59. result
  60. )
回复

使用道具 举报

4

主题

13

帖子

9

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 15:38:56 | 显示全部楼层
谢谢你,出租车,
 
我加载了代码,但每当函数要求我输入另一个前导时,我仍然无法使其运行。它会按“Y”或“N”或“enter”结束函数。我找不到我做错了什么。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:40:38 | 显示全部楼层
试试这个火腿,
 
我已经包括了一个错误处理程序,并更新了变量设置和编码,以适应用户错误。
 
  1. (defun c:bom  (/ *error ovar vlst ip int1 st1 st2 ldr2 pt2)
  2. (defun *error*  (msg)
  3.    (if    ovar
  4.      (mapcar 'setvar vlst ovar))
  5.    (princ (strcat "\nError: " (strcase msg)))
  6.    (princ))
  7. (setq    vlst '("CMDECHO" "ORTHOMODE" "OSMODE" "ATTREQ" "CLAYER")
  8.    ovar (mapcar 'getvar vlst))
  9. (mapcar 'setvar (cdr (reverse vlst)) '(1 0 0 0))
  10. (if (not (tblsearch "LAYER" "TEXT"))
  11.    (command "-layer" "m" "TEXT" "")
  12.    (setvar "CLAYER" "TEXT"))
  13. (if (findfile "bom.dwg")
  14.    (progn
  15.      (if (and (setq ip (getpoint "\nInsertion Point: "))
  16.           (not (initget 5))
  17.           (setq int1 (getint "\nItem Number: ")
  18.             st1  (getstring "\nLeft Text: ")
  19.             st2  (getstring "\nRight Text: ")))
  20.    (progn
  21.      (command "-insert" "bom" ip "" "" "" int1 st1 st2)
  22.      (setq ldr2 "Yes")
  23.      (while (and (= ldr2 "Yes")
  24.              (setq pt1 (getpoint ip "\nConnect to: ")))
  25.        (setq pt2 (polar ip (angle ip pt1) 0.1625))
  26.        (command "_line" pt2 pt1 "")
  27.        (setq ldr2 (GetKeyPress
  28.             '(("Y" "Yes") ("N" "No")) ; keys allowed, not case sensitive, & return value
  29.             "Yes" ; default when ENTER is pressed
  30.             "Do you need an extra leader? (Y/N) [Yes]:" ; message prompt
  31.             nil ; use default error message
  32.             ))))
  33.    (princ "\n<!> Block Information Not Correct <!>")))
  34.    (princ "\n<!> Block Not Found <!>"))
  35. (mapcar 'setvar vlst ovar)
  36. (princ))
  37. ;;  GetKeyPress.lsp
  38. ;;  CAB  version 1.0  03/26/09
  39. ;;  Get one key press from user similar to GetKword
  40. ;;  keys = list of key char & return value  '(("Y" "Yes")("N" "No"))
  41. ;;  def = result if ENTER is pressed  nil or "Yes" or "No" etc
  42. ;;        if nil then Enter is dissallowed
  43. ;;  msg = the prompt nil = "Press a key"
  44. ;;  emsg = the error message nil = "Incorrect keypress."
  45. (defun GetKeyPress  (keys def msg emsg / input result)
  46. (or msg (setq msg "Press a key"))
  47. (or emsg (setq emsg "Incorrect keypress."))
  48. (princ (strcat "\n" msg))
  49. (while (null result)
  50.    (and (= (car (setq input (grread))) 2) ; keyboard entry
  51.     (< 31 (setq input (cadr input)) 255) ; a key was pressed
  52.     )
  53.    (cond
  54.      ((listp input)) ; not a keypress
  55.      ((setq result (assoc (strcase (chr input)) keys))
  56.       (setq result (cadr result))
  57.       )
  58.      ((and (= input 13) def)
  59.       (setq result def)
  60.       )
  61.      ((princ (strcat "\n" emsg "\n" msg)))
  62.      )
  63.    )
  64. result
  65. )
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 15:44:32 | 显示全部楼层
哎呀,我省略了代码以防止区分大小写。
修订版本:
  1. 10
回复

使用道具 举报

4

主题

13

帖子

9

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 15:47:45 | 显示全部楼层
哇!你是了不起的出租车!!!代码看起来有点复杂,但我已经看过了,现在我了解了很多。非常感谢。
 
祝你有美好的一天!!!
回复

使用道具 举报

4

主题

13

帖子

9

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 15:51:16 | 显示全部楼层
谢谢李,谢谢你的帮助!!!你们太棒了!!!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:53:46 | 显示全部楼层
 
 
没问题-我确实需要更详细地研究grread函数-我自己只使用过一两次,但当你知道如何正确使用它时,调用它是一个非常强大的命令
 
干杯伙计们,
 
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 22:03 , Processed in 0.803835 second(s), 70 queries .

© 2020-2025 乐筑天下

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