I use this (I don't know the author), maybe it will help:
;;; remove polyline segments that have 0 length
(defun rh:del_dup_pts (lst fuzz / n_lst)
(while (> (length lst) 1) (if (> (distance (car lst) (cadr lst)) fuzz) (setq n_lst (cons (car lst) n_lst))) (setq lst (cdr lst)))
(setq n_lst (cons (car lst) n_lst))
(reverse n_lst)
);end_defun
(vl-load-com)
(defun c:plz ( / *error* ss fuzz vtot cnt ent elst obj vlst vno nvno)
(defun *error* ( msg )
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
(princ)
);_end_*error*_defun
(setq ss (ssget '((0 . "LWPOLYLINE"))) fuzz 1.0e-4 vtot 0)
(cond (ss
(repeat (setq cnt (sslength ss))
(setq ent (ssname ss (setq cnt (1- cnt)))
elst (entget ent)
obj (vlax-ename->vla-object ent)
vlst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) elst))
vno (length vlst)
);end_setq
(cond ( (and (= :vlax-true (vlax-get-property obj 'closed)) (equal (car vlst) (last vlst) fuzz))
(setq vlst (rh:del_dup_pts (reverse (cdr (reverse vlst))) fuzz))
)
( (and (= :vlax-false (vlax-get-property obj 'closed)) (equal (car vlst) (last vlst) fuzz))
(setq vlst (rh:del_dup_pts (reverse (cdr (reverse vlst))) fuzz))
(vlax-put-property obj 'closed :vlax-true)
)
(t
(setq vlst (rh:del_dup_pts vlst fuzz))
)
);end_cond
(setq nvno (length vlst))
(vlax-put obj 'coordinates (apply 'append vlst))
(setq vtot (+ vtot (- vno nvno)))
);end_repeat
(princ (strcat "\n" (itoa vtot) " Nodes removed from " (itoa (sslength ss)) (if (> (sslength ss) 1) " Polylines" " Polyline")))
)
);end_cond
(princ)
);end_defun