- (defun vxs(e / p a b n ob q et d d1 en et)
- (setq a(entget e)ob(vlax-ename->vla-object e)et(cdr(assoc 0 a))n 0 p nil d nil)
- (cond((="LWPOLYLINE"et)
- (repeat(length a)(setq b (nth n a) n (+ n 1))
- (if (= 10 (car b))(progn
- (setq q(list (cadr b) (caddr b))d1(vlax-curve-getDistAtPoint ob q))
- (if p (if (not(member d1 d)) (setq p (append p (list q))d (append d (list d1))))
- (setq p (list q)))))))
- ((="POLYLINE"et)
- (SETQ EN (ENTGET (SETQ E (ENTNEXT E))))
- (WHILE (/= (CDR (ASSOC 0 EN)) "SEQEND")
- (SETQ q (CDR (ASSOC 10 EN))d1(vlax-curve-getDistAtPoint ob q)q(reverse(cdr(reverse q))))
- (if p(if (not(member d1 d)) (setq p (append p (list q))d (append d (list d1))))(setq p(list q)))
- (SETQ EN (ENTGET (SETQ E (ENTNEXT E)))))
- (setq p(reverse p))))P)
- ;;示例(HHickSegEndPt (car(setq en(entsel))) (cadr en))
- (defun HHickSegEndPt (obj p / pp n)
- (setq pp (vlax-curve-getclosestpointto obj (trans p 1 0))
- n (fix (vlax-curve-getparamatpoint obj pp))
- )
- (setq ll (length (vxs obj)));;避免最后一个点出创,加个判断(多这一句)
- (list
- (vlax-curve-getPointAtParam obj n)
- (if (> (+ n 1) (- ll 1))
- (vlax-curve-getPointAtParam obj 1);;避免最后一个点出创,加个判断(多这一句)
- (vlax-curve-getPointAtParam obj (1+ n))
- )
- )
- )
- ;3、点表生成多段线
- (defun makepl (lst / pt)
- (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(8 . "XDDX") (cons 90 (length lst)) (cons 70 128))
- (mapcar '(lambda (pt)(cons 10 pt)) lst ))
- ) )
- (defun c:ed1 (/ p1 p2 j1 j2 jd a b ) ;p1 p2 j1 j2 jd
- (setq p1 (entsel "\n请选择多段线需要延伸端点1:")
- p2 (entsel "\n请选择多段线需要延伸端点1:")
- )
- (setq j1 (HHickSegEndPt (car p1) (cadr p1))
- j2 (HHickSegEndPt (car p2) (cadr p2))
- )
- (setq jd (inters (CAR J1)(CADR J1) (CAR J2)(CADR J2) nil)
- )
- (setq a (vxs (car p1) ) b (vxs (car p2) )
- )
- (if ( > (distance (CAR J1) jd) (distance (CAdR J1) jd) ) (setq a a) (setq a (reverse a) ) )
- (if ( > (distance (CAR J2) jd) (distance (CAdR J2) jd) ) (setq b (reverse b) ) (setq b b) )
- (makepl (append a (list jd) b ) )
- (entdel (car p1)) (entdel (car p2))
- (PRINC)
- )
|