I got the mext function from this forum and I am modifying to add vertices to the polyline. One of the condition is that if the intersection point of the lines and the polyline has a vertex, subject to a fuzz, then the vertex is not created. If not then add a new vertex. The function I created do not seem to do it.
Hope some gurus can help me out.
(defun c:mext (/ ang c e lines lwp lyr ptlst pts ss pt1 param)
(if (setq ss (ssget ":L" '((0 . "LWPOLYLINE,LINE,SPLINE"))))
(progn (mapcar '(lambda (e)
(if (wcmatch (cdr (assoc 0 (entget e))) "LINE")
(setq lines (cons e lines))
(setq lwp (cons e lwp))
)
)
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
)
(if (and lwp lines)
(foreach l (mapcar 'vlax-ename->vla-object lines)
(setq ang (vla-get-angle l)
lyr (vla-get-layer l)
ptlst nil
)
;;;
(foreach pl (mapcar 'vlax-ename->vla-object lwp)
(if (and (vlax-property-available-p pl 'closed)
(zerop (vlax-get pl 'closed))
(setq c t)
)
(vlax-put pl 'closed -1)
)
(if (setq pts (vlax-invoke l 'intersectwith pl acextendthisentity))
(progn
(while pts
(setq ptlst (cons (setq aPt (list (car pts) (cadr pts))) ptlst))
;;
(setq param (vlax-curve-getParamAtPoint
(vlax-vla-object->ename pl)(car ptlst)))
(setq pt1 (vlax-curve-getpointatparam (vlax-vla-object->ename pl) (fix param)))
(setq pt2 (vlax-curve-getpointatparam (vlax-vla-object->ename pl) (fix (1+ param))))
(cond
((and param (> param (fix param)) (equal (- param (fix param)) 1.0 0.00000005))
(vlax-invoke pl 'addvertex (+ (fix param) 1)aPt)
)
((and param (>= (- param (fix param))0.0000005))
(vlax-invoke pl 'addvertex (+ (fix param) 1)aPt)
)
);cond
;;
(setq pts (cdddr pts))
)
)
)
(if c
(progn (vlax-put pl 'closed 0) (setq c nil))
)
);foreach pl
;;;
(if ptlst
(progn
(setq ptlst (vl-sort ptlst
(function (lambda (d1 d2)
(if (equal ang 0.0 pi)
(> (car d1) (car d2))
(< (cadr d1) (cadr d2))
)
)
)
)
)
(while ptlst
(entmakex (list '(0 . "LINE")
(cons 8 lyr)
(cons 10 (car ptlst))
(cons 11 (cadr ptlst))
)
)
(setq ptlst (cddr ptlst))
)
(vla-delete l)
)
)
)
)
)
)
(princ)
)