;文件名:PB.lsp
;;功能说明:标注实际开挖线各点与设计开挖线之间的距离
;;;修改时间:2015-01-07 ss en v-en pc ss1 en1 po-li n p11 pt pt@curve osm
(vl-load-com)
(defun c:PB(/ )
(setq osm (getvar "osmode"))
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(while
(progn
(prompt "\n请选择设计开挖线:")
(not(setq ss(ssget ":s" '((0 . "CIRCLE,*POLYLINE")))))
);end progn
(prompt "\n>>>")
);end while
(setq en(ssname ss 0)
v-en(vlax-ename->vla-object en)
)
(setq pc(find-centerpoint en));找设计开挖线的型心
(while(progn(prompt "\n请选择实际开挖线:")
(not(setq ss1(ssget ":s" '((0 . "*POLYLINE")))))
);end progn
(prompt "\n>>>")
);end while
(setq en1(ssname ss1 0))
(setq po-li (vl-remove-if 'not (mapcar '(lambda (x) (if (= (car x) 10) (cdr x))) (entget en1))));取多段线顶点表
(initget 6)
(setq n (getint "\n 请输入实际开挖线上标注间隔数(默认为0):"))
(if(null n)(setq n 0))
(if(/= n 0)(setq po-li(get-new-point-list po-li n)));end if
(foreach pt po-li
(setq pt@curve(vlax-curve-getClosestPointTo v-en pt))
(if(> (distance pt pc) (distance pt@curve pc));如果超挖
(progn
(setq p11 (polar pt@curve (angle pt@curve pt) (* 2 (distance pt pt@curve))))
;(make-dimension pt pt@curve p11 "隧道超挖+")
(make-dimension pt pt@curve p11 "+" 3);箭头及线颜色3 绿色
; (command "_.pline" P11 pc "")
);end progn
);end if
(if(" 1);箭头及线颜色1 红色
; (command "_.pline" Pt p11 "")
);end progn
);end if
);end foreach
(setvar "osmode" osm)
(princ)
);end defun
;;;sub-routine1
(defun find-centerpoint(en / po-li n y pc)
(setq entda(entget en)
ename(cdr(assoc 0 entda)))
(if(= ename "CIRCLE")
(setq pc(cdr(assoc 10 entda)))
(progn
(setq po-li (vl-remove-if 'not (mapcar '(lambda (x) (if (= (car x) 10) (cdr x))) entda)))
(setq n(length po-li))
(setq y(apply 'mapcar (cons '+ po-li)))
(setq pc(mapcar '/ y (list n n n)))
);progn
);end if
);end defun
;;;sub-routine2
(defun make-dimension (p14 p13 p11 dimsty ys)
(entmake (list '(0 . "DIMENSION")
'(100 . "AcDbEntity")
'(100 . "AcDbDimension")
(cons 10 p14)
(cons 11 p11)
'(70 . 33)
(cons 1 dimsty);前缀符号
(cons 3 "超欠挖")
'(100 . "AcDbAlignedDimension")
(cons 13 p13)
(cons 14 p14)
(cons 62 ys) ;箭头及线颜色
)
);endmake
);end defun
;;;sub-routine3
;;;间隔N个数取点表
(defun get-new-point-list(li n / s-li i k)
(setq s-li nil i 0 k (1+ n))
(while(nth i li)
(setq s-li(cons (nth i li) s-li))
(setq i(+ i k))
);end while
(reverse s-li)
);end defun