本帖最后由 荒野孤行 于 2017-9-1 18:22 编辑
因在某些行业设计的图纸中,多段线要求封闭,但是有时填充时发现多段线不是闭合的,但是如果直接封闭,可能对相邻的线产生影响,故采用查找功能,效果图如下:
附上第一种程序写法的源码:
- ;;;*****查悬挂线 程序开始*****
- (defun c:t1 (/ ptlist)
- (princ "\n★功能:查找断开的曲线。\n")
- (setvar "pickadd" 1)
- (setvar "osmode" 15359)
- (setvar "PICKDRAG" 0)
- (setvar "cmdecho" 0)
- (command "undo" "be")
- (princ "\n选取多段线:")
- (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE"))))
- (if (not ss)
- (progn (princ "\n提示:未选取对象.") (exit))
- )
- (initget 7)
- (setq ptbase (getpoint "\n指定标记引出线的位置点:"))
- (setvar "osmode" 0)
- (setq i 0
- num (sslength ss)
- )
- (command "color" "Bylayer")
- (command "LAYER" "M" "层-未闭合线" "C" "250" "层-未闭合线" "")
- (command "LAYER" "M" "层-标记" "C" "1" "层-标记" "")
- (repeat num
- (setq entnam (ssname ss i)
- obj (vlax-ename->vla-object entnam)
- )
- (if (not (vlax-curve-isclosed obj))
- (progn
- (setq pt_start (vlax-curve-getstartpoint obj)
- pt_end (vlax-curve-getendpoint obj)
- ptlist (cons (list pt_start pt_end) ptlist)
- )
- (setq en (entget entnam))
- (entmod (subst (cons 8 "层-未闭合线") (assoc 8 en) en))
- )
- )
- (setq i (+ i 1))
- )
- (if (not ptlist)
- (alert "提示:恭喜你,没有发现未闭合的对象!\n")
- (progn
- (foreach pt ptlist
- (command "PLINE" (car pt) ptbase (cadr pt) "")
- )
- (alert
- "提示:抱歉,发现了未闭合的对象!\n已将其置于“层-未闭合线”图层。断开位置见参照线指引。\n"
- )
- )
- )
- (command "undo" "e")
- (setvar "osmode" 15359)
- (princ)
- )
- ;;;*****查悬挂线 程序结束*****
|