试试这个火腿,
我已经包括了一个错误处理程序,并更新了变量设置和编码,以适应用户错误。
- (defun c:bom (/ *error ovar vlst ip int1 st1 st2 ldr2 pt2)
- (defun *error* (msg)
- (if ovar
- (mapcar 'setvar vlst ovar))
- (princ (strcat "\nError: " (strcase msg)))
- (princ))
- (setq vlst '("CMDECHO" "ORTHOMODE" "OSMODE" "ATTREQ" "CLAYER")
- ovar (mapcar 'getvar vlst))
- (mapcar 'setvar (cdr (reverse vlst)) '(1 0 0 0))
- (if (not (tblsearch "LAYER" "TEXT"))
- (command "-layer" "m" "TEXT" "")
- (setvar "CLAYER" "TEXT"))
- (if (findfile "bom.dwg")
- (progn
- (if (and (setq ip (getpoint "\nInsertion Point: "))
- (not (initget 5))
- (setq int1 (getint "\nItem Number: ")
- st1 (getstring "\nLeft Text: ")
- st2 (getstring "\nRight Text: ")))
- (progn
- (command "-insert" "bom" ip "" "" "" int1 st1 st2)
- (setq ldr2 "Yes")
- (while (and (= ldr2 "Yes")
- (setq pt1 (getpoint ip "\nConnect to: ")))
- (setq pt2 (polar ip (angle ip pt1) 0.1625))
- (command "_line" pt2 pt1 "")
- (setq ldr2 (GetKeyPress
- '(("Y" "Yes") ("N" "No")) ; keys allowed, not case sensitive, & return value
- "Yes" ; default when ENTER is pressed
- "Do you need an extra leader? (Y/N) [Yes]:" ; message prompt
- nil ; use default error message
- ))))
- (princ "\n<!> Block Information Not Correct <!>")))
- (princ "\n<!> Block Not Found <!>"))
- (mapcar 'setvar vlst ovar)
- (princ))
- ;; GetKeyPress.lsp
- ;; CAB version 1.0 03/26/09
- ;; Get one key press from user similar to GetKword
- ;; keys = list of key char & return value '(("Y" "Yes")("N" "No"))
- ;; def = result if ENTER is pressed nil or "Yes" or "No" etc
- ;; if nil then Enter is dissallowed
- ;; msg = the prompt nil = "Press a key"
- ;; emsg = the error message nil = "Incorrect keypress."
- (defun GetKeyPress (keys def msg emsg / input result)
- (or msg (setq msg "Press a key"))
- (or emsg (setq emsg "Incorrect keypress."))
- (princ (strcat "\n" msg))
- (while (null result)
- (and (= (car (setq input (grread))) 2) ; keyboard entry
- (< 31 (setq input (cadr input)) 255) ; a key was pressed
- )
- (cond
- ((listp input)) ; not a keypress
- ((setq result (assoc (strcase (chr input)) keys))
- (setq result (cadr result))
- )
- ((and (= input 13) def)
- (setq result def)
- )
- ((princ (strcat "\n" emsg "\n" msg)))
- )
- )
- result
- )
|