repeat中提示参数错误
(defun C:ff ( / &dis1 &dis2 &k1 &n1&p1 p2 &ss1 &len os strtemp strtemp_ele ele k g)
(if (null vlax-dump-object) (vl-load-com) )
(setq &ss1 '("LINE" "LWPOLYLINE" "CIRCLE" "ARC" "HELIX" "ELLIPSE" "SPLINE" "POLYLINE")) ;曲线有起点:直线,多段线,圆,圆弧,螺旋对象,椭圆,样条曲线,二维多段线
(setq &k1 (entsel "\n请选择曲线"))
(while (= nil &k1)
(setq &k1 (entsel "\n没有选择曲线,重新选择"))
)
(setq &k1 (car &k1))
(member (cdr (assoc 0 (entget &k1))) &ss1);确认是曲线
(setq &p1 (getpoint "\n选择曲线上第一点:"))
(while (not (vlax-curve-getDistAtPoint &k1 &p1))
(setq &p1 (getpoint "\n没有选在曲线上,重新选择:"))
)
(if(not lenth) ;设置全局变量lenth
(setq lenth 30);给全局变量lenth付初始值30
)
(setq &len (getstring (strcat "\n输入偏移长度:" )))
(cond
((not &len) (setq &len lenth));把全局变量len的值传递给&len
((wcmatch &len "*+*") (setq strtemp (strsplit &len "+")))
((wcmatch &len "*x*") (setq strtemp (strsplit &len "x")))
)
(setq lenth &len);把局部变量&len重新传递给全局变量lenth,以便下次使用
(setq &p1 (vlax-curve-getclosestpointto &k1 &p1));取得最近点
(setq &n1 (vlax-curve-getParamAtPoint &k1 &p1));取得参数
(setq &dis1 (vlax-curve-getDistAtParam &k1 &n1));到起点距离
(setq os (getvar "osmode"));记录对象捕捉参数
(setvar "osmode" 0);关闭对象捕捉
(setq k 0)
(setq g 1)
(setq ele 0)
(cond
((wcmatch &len "*+*")
(repeat (length strtemp)
(setq strtemp_ele(atof(nth k strtemp)))
(setq strtemp_ele(+ strtemp_ele ele))
(setq &dis2 (+ &dis1 strtemp_ele))
(setq p2 (vlax-curve-getPointAtDist &k1 &dis2))
(command "circle" p2 "1");命令行显示
(setq k(+ k 1))
(setq ele strtemp_ele)
)
)
((wcmatch &len "*x*")
(repeat atoi(car strtemp)
(setq strtemp_ele(atof(cadr strtemp)))
(setq strtemp_ele(* strtemp_ele g))
(setq &dis2 (+ &dis1 strtemp_ele))
(setq p2 (vlax-curve-getPointAtDist &k1 &dis2))
(command "circle" p2 "1");命令行显示
(setq g(+ g 1))
)
)
)
(setq &dis2 (+ &dis1 (atof &len)))
(setq p2 (vlax-curve-getPointAtDist &k1 &dis2))
(command "circle" p2 "1");命令行显示
(setvar "osmode" os);还原对象捕捉设置
(princ)
)
; user defined function strsplit.
; strsplit splits a string with delimiter, and return a list.
; example: (strsplit "1,22,333,4444" ",") -->> ("1","22","333","4444")
; (strsplit ",1,22,333,4444," ",")-->> ("" "1" "22" "333" "4444" "")
(defun strsplit(datastr delimiter)
(setq strlist '()
str ""
)
(setq n (strlen datastr))
(setq i 1)
(repeat n
; s is a single letter, starts from the first to the end.
(setq s (substr datastr i 1))
;
(if (/= s delimiter)
; when s is't a delimiter
(progn
(setq str (strcat str s))
; if s is the last letter
(if (= i n)
(setq strlist (cons str strlist))
)
)
; when s is a delimiter
(progn
(setq strlist (cons str strlist))
(setq str "")
; if delimiter is the last letter
(if (= i n)
(setq strlist (cons "" strlist))
)
)
)
(setq i (1+ i))
)
; reverse list and retrun it
(reverse strlist)
)
每次运行到红色字体处,提示参数错误,我知道repeat 后面的n需要的是整数且正数类型,难道atoi这个函数不对吗?
你的括号呢 (repeat (atoi (car strtemp)) 烟盒迷唇 发表于 2021-4-25 07:25
(repeat (atoi (car strtemp))
最近怎么老是出这种低级的问题,我还检查了好几遍 竟然没看出来 不严谨执行这个操作(car strtemp)之前应该判断下strtemp是不是为空,为空的在来个atoi也会报错。 jun353835273 发表于 2021-4-25 13:33
不严谨执行这个操作(car strtemp)之前应该判断下strtemp是不是为空,为空的在来个atoi也会报错。
这是cond下面的语句,如果为空,前面就跳过去了,到不了这一句
页:
[1]