PDA

View Full Version : Remove duplicate points in polyline


boesiii
2007-03-23, 02:29 AM
Does anybody have a routine for a open ended polyline that will remove consecutive duplicate points. I have a routine that will select all the objects touching a polyline but it will not work if their are consecutive duplicate points.

mohobrien
2007-03-25, 01:29 AM
This is a straight cut and paste of the acad code in the old pljoin command. (defun c:remdupvert (/)
; choose the polyline
(setq ent (entget (car (entsel))))
(acet-lwpline-remove-duplicate-pnts ent)
(princ)
)
;Takes an entity list of lwpolylines and modifies the object
;removing neighboring duplicate points. If no duplicated points
;are found then the object will not be passed to (entmod ).
;Returns the new elist when done.
(defun acet-lwpline-remove-duplicate-pnts (e1 / a n lst e2)
(setq n 0)
(repeat (length e1)
(setq a (nth n e1)) ;setq
(cond
((not (equal 10 (car a)))
(setq e2 (cons a e2))
) ;cond #1
((not (equal (car lst) a))
(setq lst (cons a lst)
e2 (cons a e2)
) ;setq
) ;cond #2
) ;cond close
(setq n (+ n 1)) ;setq
) ;repeat
(setq e2 (reverse e2))
(if (and e2
(not (equal e1 e2))
lst
) ;and
(progn
(if (equal 1 (length lst))
(progn
(entdel (cdr (assoc -1 e1)))
(setq e2 nil)
) ;progn then single vertex polyline so delete it.
(progn
(setq e2 (subst (cons 90 (length lst)) (assoc 90 e2) e2)
) ;setq
(entmod e2)
) ;progn else
) ;if
) ;progn then
) ;if
e2
)