一个问题,不得其解了,请帮忙看下
我想在一条线上(由多条line,pline组成)选中一段线,自动找出整条线,用红色显示,该线的各线段名称(ename)保存在mline的列表中,我判断的时候将已经找出的线段排除了(itemexist 判断),可是结果还是会重复已经找出的线段,请各位看看这是哪里错了,3ks! 贴出你的程序段,别人才好判断。 本来上传了的,现在写在下面,帮忙看下:),主程序是findline(defun ptinpl (ename n)<BR> (setq ent (entget ename))<BR> (setq i (+ 14 (* (- n 1) 4)))<BR> (cdr (nth i ent))<BR> ;(list (nth (* n 2) plist)(nth (1+ (* n 2)) plist))<BR>)
(defun ptnofpl(ename)<BR> (setq ent (entget ename))<BR> (/ (- (length ent) 15) 4)<BR>)
(defun itemexist(mlist item / bu len i)<BR> (setq bu nil)<BR> (setq len (length mlist) i (- len 1))<BR> (while (>= i 0)<BR> (if (= (nth i mlist) item) (setq bu t i 0))<BR> (setq i (- i 1))<BR> )<BR> bu<BR>)<BR> <BR> <BR>(defun c:findline()<BR> (setq lstart nil) ;;line name list<BR> (while (not lstart)<BR> (setq lstart (car (entsel "\n选择线的起始线:")))<BR> )<BR> (setq ltype (cdr (assoc 0 (entget lstart))))<BR> (if (= (strcase ltype) "LINE")<BR> (setq pt1 (cdr (assoc 10 (entget lstart))) pt2 (cdr (assoc 11 (entget lstart))))<BR> (setq pt1 (ptinpl lstart 1) pt2 (ptinpl lstart (ptnofpl lstart)))<BR> )<BR> (setq ssl (ssget "x" (list (cons 0 "line"))))<BR> (setq sspl (ssget "x" (list (cons 0 "LWPOLYLINE"))))<BR> (setq lno (sslength ssl))<BR> (setq plno (sslength sspl))<BR> (setq num (+ lno plno))<BR> (setq isend nil)<BR> (setq mline (list lstart))
(setq count 0)<BR> (while (not isend)<BR> (setq i 0 isend t)<BR> (while (< i num)<BR> (if (< i lno)<BR> (setq ename (ssname ssl i))<BR> (setq ename (ssname sspl (- i lno)))<BR> )<BR> (if (not (itemexist mline ename))(progn<BR> (setq ent (entget ename))<BR> (setq ltype (cdr (assoc 0 ent)))<BR> (if (< i lno)<BR> (setq tpt1 (cdr (assoc 10 ent)) tpt2 (cdr (assoc 11 ent)))<BR> (setq tpt1 (ptinpl ename 1) tpt2 (ptinpl ename (ptnofpl ename)))<BR> )<BR> (if (= (distance tpt1 pt2) 0)<BR> (progn<BR> (setq mline (append mline (list ename)))<BR> (setq pt2 tpt2 isend nil i num)<BR> )<BR> (if (= (distance tpt1 pt1) 0)<BR> (progn<BR> (setq mline (append mline (list ename)))<BR> (setq pt1 tpt2 isend nil i num)<BR> ) <BR> )<BR> )<BR> (if isend<BR> (progn<BR> (if (= (distance tpt2 pt1) 0)<BR> (progn<BR> (setq mline (append mline (list ename)))<BR> (setq pt1 tpt1 isend nil i num)<BR> )<BR> (if (= (distance tpt2 pt2) 0)<BR> (progn<BR> (setq mline (append mline (list ename)))<BR> (setq pt2 tpt1 isend nil i num)<BR> )<BR> )<BR> )))<BR> ))<BR> (setq i (+ i 1))<BR> )<BR> (setq count (+ count 1))<BR> (if (>= count 20)(setq isend t))<BR> )
(foreach i mline<BR> (command "change" i "" "p" "c" "1" "")<BR> )<BR> )
页:
[1]