remove consecutive duplicate points of a pline

remove consecutive duplicate points of a pline

kibitotato
Advocate Advocate
1,296 Views
13 Replies
Message 1 of 14

remove consecutive duplicate points of a pline

kibitotato
Advocate
Advocate

¿Is it possible to have a .lsp that removes consecutive duplicate points of a opened or closed pline?

0 Likes
Accepted solutions (1)
1,297 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

One way:

EXPLODE the Polyline.

Use QSELECT or FILTER to select all Lines [and possibly Arcs?] of zero length, and ERASE them.

JOIN or PEDIT / Join what's left back into a Polyline.

I expect an AutoLisp routine could be written to do that, if that sounds like what you want.  I also expect there's something like that already out there, available for the Searching.

Kent Cooper, AIA
0 Likes
Message 3 of 14

kibitotato
Advocate
Advocate

I´m looking for a quick mode, so a lsp could be perfect. I delete this kind of duplicated points several times in one hour. Found this but doesn´t work properly for me 

(defun c:RD (/)
; 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
)

 

0 Likes
Message 4 of 14

EnM4st3r
Advocate
Advocate

what about OVERKILL

Message 5 of 14

kibitotato
Advocate
Advocate

yes it works but ideally not quick enought

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:

.... Found this but doesn´t work properly for me ....


That is never enough information.  What's not proper about it?

 

I am skeptical that a custom AutoLisp routine is going to be enough quicker than OVERKILL to justify the effort of writing one.  What makes OVERKILL not quick enough?

Kent Cooper, AIA
0 Likes
Message 7 of 14

kibitotato
Advocate
Advocate

I understand.

So, in order to be quicker, is it possible to have overkill without this window???

kibitotato_0-1715671126066.png

 

0 Likes
Message 8 of 14

EnM4st3r
Advocate
Advocate

yes, use _-OVERKILL

Example:

 

(setq ss (ssget  "_X" '((0 . "LWPOLYLINE"))))
(command "_-overkill" ss "" "_PL" "_y" "")

 

 


Or without the "_X" for manual selection:

 

(setq ss (ssget '((0 . "LWPOLYLINE"))))
(command "_-overkill" ss "" "_PL" "_y" "")

 

0 Likes
Message 9 of 14

kibitotato
Advocate
Advocate

I think that this works for all objects into the drawing. I want to work it witch only one...

0 Likes
Message 10 of 14

EnM4st3r
Advocate
Advocate

yes, with the second one you can select the objects manually

0 Likes
Message 11 of 14

kibitotato
Advocate
Advocate

Is it possible to associate it to a shortcut like WQ or something... ? Tried to edit it into .pgp but doesnt work...

0 Likes
Message 12 of 14

EnM4st3r
Advocate
Advocate
Accepted solution

yes like this. Save as .lsp

(defun c:wq (/ ss)
  (setq ss (ssget '((0 . "LWPOLYLINE"))))
  (command "_-overkill" ss "" "_PL" "_y" "")
  (princ)
)
0 Likes
Message 13 of 14

kibitotato
Advocate
Advocate
absolutely perfect!!!! thanks!!!!!!
0 Likes
Message 14 of 14

komondormrex
Mentor
Mentor

it is surely possible. check the following.

 

;**********************************************************************************************************************************************************

(defun remove_duplicates (_list / duplicateless_list)
	(while _list
		(if (not (equal (car (setq list_element (car _list))) (caar (setq _list (cdr _list)))))
			(setq duplicateless_list (append duplicateless_list (list list_element)))
		)
	)
)

;**********************************************************************************************************************************************************

(defun c:remove_duplicate_vertices (/ pline_sset deleted_number pline_dxf number_before)
	(if (setq deleted_number 0 pline_sset (ssget ":l" '((0 . "lwpolyline"))))
		(foreach pline (vl-remove-if 'listp (mapcar 'cadr (ssnamex pline_sset)))
			(setq pline_dxf (entget pline)
				  number_before (fix (vlax-curve-getendparam pline))
				  vertices_bulge_list (remove_duplicates (mapcar 'cons (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group))) pline_dxf))
				  										  			   (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 42 (car group))) pline_dxf))
													     )
									  )
			)
			(vla-put-coordinates (vlax-ename->vla-object pline)
								 (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 1 (* 2 (length vertices_bulge_list))))
								 				      (apply 'append (mapcar 'car vertices_bulge_list))
								 )
			)
			(setq deleted_number (+ deleted_number (- number_before (fix (vlax-curve-getendparam pline)))))
			(setq index 0)
			(foreach vertex vertices_bulge_list
				(vla-setbulge (vlax-ename->vla-object pline) index (cdr vertex))
				(setq index (1+ index))
			)
			(princ (strcat "\rTotal deleted duplicate vertices: " (itoa deleted_number)))
		)
	)
	(princ)
)

;**********************************************************************************************************************************************************