需要INITGET选项可能是
我有一个多年前写的基本代码。它根据用户输入绘制平面2d血管。我想修改代码,因此在开始时,当它要求用户以英寸为单位输入接缝到接缝的长度时,用户可以只输入以英寸为单位的尺寸,并正常运行代码,或者询问用户是否在(F)eet中。类似于“输入接缝到接缝的长度,单位为英寸或(F)eet”。非常感谢您的帮助。(defun c:vv ()
(input)
(compute)
(draw)
(whatif)(princ))
(defun input ()
(setvar "cmdecho" 0)
(command "-units" "4" "" "" "" "" "")
(setq vc (getdist "Enter vessel seam to seam length in inches..."))
(setq vd (getreal "Enter vessel diameter in inches..."))
(initget 1 "H V")(setq vo (getkword "Enter vessel orientation...(H or V)"))
(setq vb (getint "How many shellbelts? "))
(setq vs (getpoint "Select starting point..."))
(princ))
;;;compute
(defun compute ()
(setq vc1 (/ vc 2))
(setq vc2 (+ vc1 2))
(setq vcc (rtos vc 4 4))
(setq vcc1 (rtos vc1 4 4))
(setq vcc2 (rtos vc2 4 4))
;shellbelts
(setq vc3 (- vc 12))
(setq vb1 (- vb 1))
(setq vc4 (/ vc3 vb1))
(princ))
;;;draw
(defun draw ()
(setq vss (strcat "@" vcc ",0"))
(command "layer" "n" "vessel" "s" "vessel" "")
(command "line" vs vss "")
;;offset
(setq os (ssget "l"))
(command "offset" vd os vs "")
(command "insert" "vcap" vs vd "" "")
;;;mirror
(setq mc (ssget "l"))
(setq vss1 (strcat "@" vcc1 ",0"))
(setq vss2 (strcat "@" "0," vcc2))
(command "mirror" mc "" vss1 vss2 "n")
(command "layer" "n" "shellbelt" "s" "shellbelt" "")
(command "insert" "shellbelt" vs vd "" "")
(command "array" "l" "" "r" "" vb vc4)
(setq lay_name2 "shellbelt")
(setq ss1 (ssget "X" (list(cons 8 lay_name2))))
(command "move" ss1 "" "0,0" "@6,0")
(setq lay_name1 "vessel")
(command "-units" "2" "" "" "" "" "")
(setq ss2 (ssget "X" (list(cons 8 lay_name1))))
(princ))
(defun whatif ()
(if (= "V" vo)
(command "rotate" ss1 ss2 "" vs "90"))
(princ)) 伙计们,我明白了。我一直在努力思考这个问题。我最后添加了以下内容:
(initget 1 "I F")(setq IFIF (getkword "\nEnter vessel seam to seam length in (I)nches or (F)eet..."))
(cond ((= IFIF "I")
(setq vc (getdist "Enter vessel seam to seam length in inches...")))
((= IFIF "F")
(setq vvv (getdist "Enter vessel seam to seam length in feet...")))
(setq vc (* vvv 12))
)
这就成功了。再次感谢! 哼,我只是在想,如果还有人想插话的话。我该如何将其编辑为我最初所说的内容。如果用户甚至不需要输入(I)英寸,那么初始输入总是以英寸为单位。仅在尺寸单位为英尺的情况下添加(F)选项。如果用户输入14-6,它将计算出英尺乘以12,然后再加上额外的英寸,并使用该数字作为总数。 或者提示输入文本并使用(distof)。 我会把一个不同方向的输入12或f12作为一个字符串,看第一个字符,如果它的f,那么它的脚去掉f等乘以12,我没有看代码关闭。缺点是不能使用getdist。但是,如果你的打字输入99%的时间,那么它的确定。 一种简单的方法:
(while (not (numberp (setq vc (progn (initget "Feet Inches") (getdist "\nSpecify length or : ")))))
(cond
( (= vc "Feet")
(alert "Feet were specified, prompting back for a length.") ; do something here
)
( (= vc "Inches")
(alert "Inches were specified, prompting back for a length.") ; do something here
)
); cond
); while
或定义自定义子功能(非相关示例):
; Example for (_GetWithOption):
(defun C:test ( / p )
(defun pointp ( p ) (and (vl-consp p) (member (length p) '(2 3)) (vl-every 'numberp p)))
(while
(not
(pointp
(setq p
(_GetWithOption getpoint "Specify a point or "
'(
("Inches" (alert "Inches were specified, prompting back for a point."))
("Feet" (alert "Feet were specified prompting back for a point."))
)
); _GetWithOption
); setq p
); pointp
); not
); while
(princ)
); defun C:test for (_GetWithOption)
; getfoo - getXXX function, i.e.: getpoint/getint/getreal/getstring
; msg - message
; aL - assoc list of (<Option > <foo>)
(defun _GetWithOption ( getfoo msg aL / v itm r )
(defun stringp ( s ) (eq 'STR (type s)) )
(cond
( (not (eq 'SUBR (type getfoo))) (princ "\nInvalid \"getfoo\" provided.") )
( (not (eq 'STR (type msg))) (princ "\nInvalid \"msg\" provided.") )
( (not (and (vl-consp aL) (vl-every 'vl-consp aL) (vl-every 'stringp (mapcar 'car aL)))) (princ "\nInvalid \"aL\" provided.") )
(T
(initget (apply 'strcat (mapcar '(lambda (x) (strcat (car x) " ")) aL)))
(setq v (getfoo (strcat "\n" msg "[" (vl-string-left-trim "/" (apply 'strcat (mapcar '(lambda (x) (strcat "/" (car x))) aL))) "]")))
(or (and (setq itm (assoc v aL)) (setq r (car itm)) (progn (eval (cadr itm)) T)) (setq r v) )
)
); cond
r
); defun _GetWithOption
一个缺点是,这种提示会强制用户输入(不能通过按键中断提示),因此这可能更合适:
5
正如您所见,整个过程都是关于使用cond并将其包装在while循环中。
页:
[1]