其实并不是出什么错了,就是捕捉交点的问题。由于离得太近,而捕捉功能又是打开的,所以就这样了。。。
- (vl-load-com)
- (defun err(msg)
- (princ msg)
- (setq *error* errtmp)
- (setvar "osmode" os)
- (princ)
- )
- (defun setcolor(sname color / sinf)
- (setq sinf (entget sname))
- (if (assoc 62 sinf)
- (setq sinf (subst (cons 62 color) (assoc 62 sinf) sinf))
- (setq sinf (append sinf (list (cons 62 color))))
- )
- (entmod sinf)
- )
- ;函数:GetInterPOint
- ;功能:返回两个对象的所有交点
- ;参数: ent1、ent2 均为ename对象
- (defun GetInterPoint (ent1 ent2 / ax_ent_1 ax_ent_2 intpoints points i)
- (setq ax_ent_1 (vlax-ename->vla-object ent1)
- ax_ent_2 (vlax-ename->vla-object ent2)
- )
- (setq intpoints (vla-intersectwith ax_ent_1 ax_ent_2 acextendnone))
- (setq intpoints (vlax-variant-value intpoints))
- (setq i 0)
- (if (> (vlax-safearray-get-u-bound intpoints 1) 0)
- (repeat (/ (+ 1
- (- (vlax-safearray-get-u-bound intpoints 1)
- (vlax-safearray-get-l-bound intpoints 1)
- )
- )
- 3
- )
- (setq points (append points (list (list
- (vlax-safearray-get-element intpoints i)
- (vlax-safearray-get-element intpoints (+ i 1))
- (vlax-safearray-get-element intpoints (+ i 2))
- )))
- )
- (setq i (+ 3 i))
- )
- )
- points
- )
- (defun c:Brk( / pt1 pt2 pt param1 param2 param ent entv ent2 ent2v)
- ;(setq pt1 (getpoint "\n选择交点一:"))
- ;(setq pt2 (getpoint "\n选择交点二:"))
- (setq errtmp *error*)
- (setq *error* err)
- (setq os (getvar "osmode"))
- (setvar "osmode" 0)
- (setvar "cmdecho" 0)
- (prompt "\n选择线...");这里就是选择两条线,怎么提示我也不清楚,你自己改吧.
- (setq ss (ssget '((0 . "polyline"))))
- (prompt "\n选择红线...")
- (setq ent (car (entsel)))
- (setq pt1 (car (getinterpoint (ssname ss 0) ent)))
- (setq pt2 (car (getinterpoint (ssname ss 1) ent)))
- (setq entv (vlax-ename->vla-object ent))
- (setq param1 (vlax-curve-getParamAtPoint entv pt1))
- (setq param2 (vlax-curve-getParamAtPoint entv pt2))
- (if (< param2 param1)
- (progn
- (setq pt pt2
- pt2 pt1
- pt1 pt)
- (setq param param2
- param2 param1
- param1 param)
- )
- )
- (setq pt1 (vlax-curve-getPointAtDist entv (- (vlax-curve-getDistAtParam entv param1) 0.5)))
- (setq pt2 (vlax-curve-getPointAtDist entv (+ (vlax-curve-getDistAtParam entv param2) 0.5)))
- (setcolor ent 4)
- (setvar "osmode" 0)
- (command "_.break" (list ent pt1) "f" pt1 "@")
- (setcolor (entlast) 1)
- (setq ent2 (entlast))
- (setq ent2v (vlax-ename->vla-object ent2))
- (command "_.break" (list ent2 pt2) "f" pt2 "@")
- (setcolor (entlast) 4)
- (setq *error* errtmp)
- (setvar "osmode" os)
- (princ)
- )
|