为什么这程序不能执行第二次呢
在论坛里面的一个公差程序,想改可以带记忆的,可是不知道为什么,改成这样后,第一次命令可以正常使用,执行第二次命令的时候就会显示:错误: 参数类型错误: numberp: "0.1",0.1是我上次输入的数字,请高人帮忙看看,是哪里出问题了。(DEFUN C:G5()(if (and
(if t1
(if (setq t11 (getstring (strcat "\n请指定上限公差值+<" (rtos t1) ">:")))
(setq t1 t11)
)
(setq t1 (getstring "\n请指定上限公差值+: "))
)
(if t2
(if (setq t21 (getstring (strcat "\n请指定下限公差值-<" (rtos t2) ">:")))
(setq t2 t21)
)
(setq t2 (getstring "\n请指定上限公差值-: "))
)
(princ "\n选择尺寸: ")
(setq ss (ssget '((0 . "DIMENSION")))))
(progn
(if(= t1 t2)
(setq txt (strcat "<>%%P"t1" "))
(setq txt (strcat "<>{\\H0.7x;\\S"t1"^"t2";}")))
(repeat (setq i (sslength ss))
(setq ent (entget(ssname ss (setq i (1- i)))))
(entmod (subst (cons 1 txt) (assoc 1 ent) ent))
)
)
)
(princ)
) 括号里面加上局部变量就行了。
(DEFUN C:G5 (/ t1 t11 t2 t21 ss txt i ent)
(if (and
(if t1
(if (setq t11
(getstring (strcat "\n请指定上限公差值+<" (rtos t1) ">:")
)
)
(setq t1 t11)
)
(setq t1 (getstring "\n请指定上限公差值+: "))
)
(if t2
(if (setq t21
(getstring (strcat "\n请指定下限公差值-<" (rtos t2) ">:")
)
)
(setq t2 t21)
)
(setq t2 (getstring "\n请指定上限公差值-: "))
)
(princ "\n选择尺寸: ")
(setq ss (ssget '((0 . "DIMENSION"))))
)
(progn
(if (= t1 t2)
(setq txt (strcat "<>%%P" t1 " "))
(setq txt (strcat "<>{\\H0.7x;\\S" t1 "^" t2 ";}"))
)
(repeat (setq i (sslength ss))
(setq ent (entget (ssname ss (setq i (1- i)))))
(entmod (subst (cons 1 txt) (assoc 1 ent) ent))
)
)
)
(princ)
)
(setq t1 (getstring "\n请指定上限公差值+: "))
xxxxxx (rtos t1) xxxxxx
T2也是同样的型别错误 sicky111 发表于 2014-11-2 14:57 static/image/common/back.gif
括号里面加上局部变量就行了。
(DEFUN C:G5 (/ t1 t11 t2 t21 ss txt i ent)
(if (and
谢谢,可是这样就达不到记忆的效果了 Andyhon 发表于 2014-11-2 15:04 static/image/common/back.gif
(setq t1 (getstring "\n请指定上限公差值+: "))
xxxxxx (rtos t1) xxxxxx
请问那应该怎样表达呢 建议您搜寻 Ustr 的使用例句 http://bbs.mjtd.com/forum.php?mod=viewthread&tid=85976 Ustr不知道是怎么样用的 本帖最后由 ZZXXQQ 于 2014-11-3 21:10 编辑
(defun C:G5 ()
(if (and
(if (setq t11 (getreal
(strcat "\n请指定上限公差值+" (if t1 (strcat "<" (rtos t1 2) ">: ") ": "))))
(setq t1 t11) t1
)
(if (setq t21 (getreal
(strcat "\n请指定下限公差值-" (if t2 (strcat "<" (rtos t2 2) ">: ") ": "))))
(setq t2 t21) t2
)
(princ "\n选择尺寸: ")
(setq ss (ssget '((0 . "DIMENSION")))))
(progn
(if (equal t1 t2 1e-6)
(setq txt (strcat "<>%%P" (rtos t1 2)))
(setq txt (strcat "<>{\\H0.7x;\\S" (rtos t1 2) "^" (rtos t2 2) ";}"))
)
(repeat (setq i (sslength ss))
(setq ent (entget(ssname ss (setq i (1- i)))))
(entmod (subst (cons 1 txt) (assoc 1 ent) ent))
)
))
(princ)
)
(defun c:tt ( / s sle slem )
(or *duprem* (setq *duprem* 0.2))
(or *dupre* (setq *dupre* 0.2))
(setq sle (getreal (strcat "\n上公差 <" (rtos *duprem*) ">: ")))
(setq slem (getreal (strcat "\n下公差 <" (rtos *dupre*) ">: ")))
(if (not sle)(setq sle *duprem*)(setq *duprem* sle))
(if (not slem)(setq slem *dupre*)(setq *dupre* slem))
(if (ssget '((0 . "dimension")))
(progn
(vlax-for o (setq s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(vla-put-tolerancedisplay o actoldeviation)
(vla-put-toleranceupperlimit o sle)
(vla-put-tolerancelowerlimit o slem)
)
(vla-delete s)
)
)(princ)
)