Deleteing polyline vertex

Deleteing polyline vertex

Anonymous
Not applicable
507 Views
13 Replies
Message 1 of 14

Deleteing polyline vertex

Anonymous
Not applicable
Does anyone have or know where I can get a lisp routine that will
delete vertices from polylines?

Thanks in advance

Joe Smetanko
M-E Companies
Westerville, Ohio
0 Likes
508 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Here's a couple of routines from my web site. Pass RV the entity name of
your polyline and the point representing which vertex to remove. Hope they
help:

;;; Removes the selected vertex from a lightweight polyline
(defun rv (e pt)
(if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
(progn
(setvar "cmdecho" 0)
(command "undo" "begin")
(entmod (drop (cons 10 (list (car pt) (cadr pt))) e))
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
)
)
)

;;; Returns the list minus the specified element
(defun drop (lst item)
(append (reverse (cdr (member item (reverse lst))))
(cdr (member item lst))
)
)

--
Get free software and more at http://www2.stonemedia.com/franko

"Joe Smetanko" wrote in message
news:38D7D484.5779BB70@mecompanies.com...
> Does anyone have or know where I can get a lisp routine that will
> delete vertices from polylines?
>
> Thanks in advance
>
> Joe Smetanko
> M-E Companies
> Westerville, Ohio
>
0 Likes
Message 3 of 14

Anonymous
Not applicable
Since Frank's code doesn't work at all
(which is actually good, because if it
did work, it could easily delete more
than one vertex), you can use the code
below to do what you need.

For example, this will delete the 5th
vertex in the polyline which was just
created:

(entmod
(DeleteVertexAt
(entget (entlast))
4
)
)

;; DelVertex.lsp Copyright 2000 Tony Tanzillo
;; (DeleteVertexAt )
;;
;; Takes an LWPOLYLINE entity data list,
;; and one or more vertex indices, and returns
;; the data list with the specified vertices
;; removed.
;;
;; is the complete entity data list.
;;
;; an integer or list of integers
;; which are the zero-based indices of the
;; vertices to be removed. The first vertex
;; is referenced by the index value 0.
;;
;; Examples:
;;
;; Delete the third vertex in an LWPOLYLINE:
;;
;; (DeleteVertexAt 2)
;;
;; Delete the second and fourth vertices:
;;
;; (DeleteVertexAt '(1 3))
;;

(defun DeleteVertexAt (pline indices / k)
(if (atom indices)
(setq indices (list indices))
)
(setq k -1)
(MapLWVertex pline
'(lambda (vertex)
(if (not (member (setq k (1+ k)) indices))
vertex
)
)
)
)

(defun maplwvertex (pline func / rslt)
( (lambda (vertices)
(while (and vertices (eq (caar vertices) 10))
( (lambda (vertex / r)
(if (setq r (apply func (list vertex)))
(setq rslt (cons r rslt))
)
(setq vertices (cddddr vertices))
)
(list
(car vertices)
(cadr vertices)
(caddr vertices)
(cadddr vertices)
)
)
)
)
(member (assoc 10 pline) pline)
)
(print (length rslt))
(append
(subst
(cons 90 (length rslt))
(assoc 90 pline)
(lwpolyheader pline)
)
(apply 'append (reverse rslt))
(list (assoc 210 pline))
)
)

(defun lwpolyheader (pline)
(if (/= (caar pline) 10)
(cons (car pline)
(lwpolyheader (cdr pline))))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;; DelVertex.lsp ;;;;;;;;;;;;;;;;;;;;;;;;;

Joe Smetanko wrote:
>
> Does anyone have or know where I can get a lisp routine that will
> delete vertices from polylines?
>
> Thanks in advance
>
> Joe Smetanko
> M-E Companies
> Westerville, Ohio

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes
Message 4 of 14

Anonymous
Not applicable
Prove it.

--
Get free software and more at http://www2.stonemedia.com/franko

"Tony Tanzillo" wrote in message
news:38D7FDF0.F96FC781@worldnet.att.net...
> Since Frank's code doesn't work at all
> (which is actually good, because if it
> did work, it could easily delete more
> than one vertex), you can use the code
> below to do what you need.
0 Likes
Message 5 of 14

Anonymous
Not applicable
Thanks for pointing out the typo. I think you'll find this works just fine.
BTW, how can you delete more than one vertex when only one vertex will match
the point you pass it? Try it yourself: (apply 'rv (entsel)) and use an
endpoint snap to select a vertex in a lwpoly.

;;; Removes the selected vertex from a lightweight polyline
(defun rv (e pt)
(if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
(progn
(setvar "cmdecho" 0)
(command "undo" "begin")
(entmod (drop e (cons 10 (list (car pt) (cadr pt)))))
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
)
)
)

;;; Returns the list minus the specified element
(defun drop (lst item)
(append (reverse (cdr (member item (reverse lst))))
(cdr (member item lst))
)
)

--
Get free software and more at http://www2.stonemedia.com/franko

"Tony Tanzillo" wrote in message
news:38D7FDF0.F96FC781@worldnet.att.net...
> Since Frank's code doesn't work at all
> (which is actually good, because if it
> did work, it could easily delete more
> than one vertex), you can use the code
> below to do what you need.
0 Likes
Message 6 of 14

Anonymous
Not applicable
BTW, AutoCAD automatically updates group code 90 and also removes the
attendant group codes 40, 41 and 42 whenever you remove a 10.

--
Get free software and more at http://www2.stonemedia.com/franko
0 Likes
Message 7 of 14

Anonymous
Not applicable
Tony Tanzillo was kind enough to point out a typo that prevented my routine
from operating properly. Here is a corrected version. In addition he pointed
out that someon may want to remove a vertex using an index number rather
than a point. With some minor tweaks, I wrote a second version to allow for
that. Here they are. Hope they help.

;;; Removes the selected vertex from a lightweight polyline
;;; using a specified point
(defun RVP (e pt)
(if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
(progn
(setvar "cmdecho" 0)
(command "undo" "begin")
(entmod (drop e (cons 10 (list (car pt) (cadr pt)))))
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
)
)
)

;;; Removes the selected vertex from a lightweight polyline
;;; using a zero-based index number
(defun RVI (e index)
(if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
(progn
(setvar "cmdecho" 0)
(command "undo" "begin")
(entmod (drop e (cons 10 (nth index (massoc 10 e)))))
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
)
)
)
;;; Returns the list minus the specified element
(defun drop (lst item)
(append (reverse (cdr (member item (reverse lst))))
(cdr (member item lst))
)
)

;;; Written by Jaysen Long
;;; Returns a list containing cdrs for every occurence of key in alist
(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
)

--
Get free software and more at http://www2.stonemedia.com/franko

"Frank Oquendo" wrote in message
news:8b8m5c$6s111@adesknews2.autodesk.com...
> Here's a couple of routines from my web site. Pass RV the entity name of
> your polyline and the point representing which vertex to remove. Hope they
> help:
>
> ;;; Removes the selected vertex from a lightweight polyline
> (defun rv (e pt)
> (if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
> (progn
> (setvar "cmdecho" 0)
> (command "undo" "begin")
> (entmod (drop (cons 10 (list (car pt) (cadr pt))) e))
> (command "undo" "end")
> (setvar "cmdecho" 1)
> (princ)
> )
> )
> )
>
> ;;; Returns the list minus the specified element
> (defun drop (lst item)
> (append (reverse (cdr (member item (reverse lst))))
> (cdr (member item lst))
> )
> )
>
> --
> Get free software and more at http://www2.stonemedia.com/franko
>
>
> "Joe Smetanko" wrote in message
> news:38D7D484.5779BB70@mecompanies.com...
> > Does anyone have or know where I can get a lisp routine that will
> > delete vertices from polylines?
> >
> > Thanks in advance
> >
> > Joe Smetanko
> > M-E Companies
> > Westerville, Ohio
> >
>
>
0 Likes
Message 8 of 14

Anonymous
Not applicable
Tony Tanzillo was kind enough to point out a typo that prevented my routine
from operating properly. Here is a corrected version. In addition he pointed
out that someone may want to remove a vertex using an index number rather
than a point. With some minor tweaks, I modified my routine to allow for
that. Here it is. Hope they help.

;;; Removes the selected vertex from a lightweight polyline
;;; using a specified point or a zero-based index
(defun rv (e pt)
(if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
(progn
(setvar "cmdecho" 0)
(command "undo" "begin")
(entmod (drop e
(cons 10
(if (= (type pt) 'LIST)
(list (car pt) (cadr pt))
(nth pt (massoc 10 e))
)
)
)
)
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
)
)
)

;;; Returns the list minus the specified element
(defun drop (lst item)
(append (reverse (cdr (member item (reverse lst))))
(cdr (member item lst))
)
)

;;; Written by Jaysen Long
;;; Returns a list containing cdrs for every occurence of key in alist
(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
)

--
Get free software and more at http://www2.stonemedia.com/franko

"Frank Oquendo" wrote in message
news:8b8m5c$6s111@adesknews2.autodesk.com...
> Here's a couple of routines from my web site. Pass RV the entity name of
> your polyline and the point representing which vertex to remove. Hope they
> help:
>
> ;;; Removes the selected vertex from a lightweight polyline
> (defun rv (e pt)
> (if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
> (progn
> (setvar "cmdecho" 0)
> (command "undo" "begin")
> (entmod (drop (cons 10 (list (car pt) (cadr pt))) e))
> (command "undo" "end")
> (setvar "cmdecho" 1)
> (princ)
> )
> )
> )
>
> ;;; Returns the list minus the specified element
> (defun drop (lst item)
> (append (reverse (cdr (member item (reverse lst))))
> (cdr (member item lst))
> )
> )
>
> --
> Get free software and more at http://www2.stonemedia.com/franko
>
>
> "Joe Smetanko" wrote in message
> news:38D7D484.5779BB70@mecompanies.com...
> > Does anyone have or know where I can get a lisp routine that will
> > delete vertices from polylines?
> >
> > Thanks in advance
> >
> > Joe Smetanko
> > M-E Companies
> > Westerville, Ohio
> >
>
>
0 Likes
Message 9 of 14

Anonymous
Not applicable
Unfortunately, I have to advise against using the
code Frank posted (and subsequently revised), as
it remains bugged.

My advice is to use the code I posted, mainly because
it works, and does not fail when there's more than one
vertex in the polyline at the same coordinate, or when
the polyline is not in the WCS.

Joe Smetanko wrote:
>
> Does anyone have or know where I can get a lisp routine that will
> delete vertices from polylines?
>
> Thanks in advance
>
> Joe Smetanko
> M-E Companies
> Westerville, Ohio

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes
Message 10 of 14

Anonymous
Not applicable
In his own style, Mr. Tanzillo has helped me create amuch more robust
routine than I originally posted. Here it is. You can pass this routine the
entity name of your polyline along with either a point or an index (0-based)
to specify the vertex to remove. Hope it helps.

;;; Removes the selected vertex from a lightweight polyline
;;; using a specified point or a zero-based index
(defun rv (e pt)
(if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
(progn
(setvar "cmdecho" 0)
(command "undo" "begin")
(entmod
(drop e
(cons 10
(if (= (type pt) 'LIST)
(progn
(setq pt (trans pt 1 (cdr (assoc -1 e))))
(list (car pt) (cadr pt))
)
(nth pt (massoc 10 e))
)
)
)
)
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
)
)
)

;;; Returns the list minus the specified element
(defun drop (lst item)
(append (reverse (cdr (member item (reverse lst))))
(cdr (member item lst))
)
)

;;; Written by Jaysen Long
;;; Returns a list containing cdrs for every occurence of key in alist
(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
)

--
Visit me at: http://www2.stonemedia.com/franko

"Joe Smetanko" wrote in message
news:38D7D484.5779BB70@mecompanies.com...
> Does anyone have or know where I can get a lisp routine that will
> delete vertices from polylines?
>
> Thanks in advance
>
> Joe Smetanko
> M-E Companies
> Westerville, Ohio
>
0 Likes
Message 11 of 14

Anonymous
Not applicable
Since your point about the WCS is valid only when trying to remove a vertex
by using a specified point, I've fixed the problem. I appreciate the heads
up. Do you have any more suggestions? BTW, multiple vertices with the same
ordinates was never a problem.

;;; Removes the selected vertex from a lightweight polyline
;;; using a specified point or a zero-based index
(defun rv (e pt)
(if (= (cdr (assoc 0 (setq e (entget e)))) "LWPOLYLINE")
(progn
(setvar "cmdecho" 0)
(command "undo" "begin")
(entmod
(drop e
(cons 10
(if (= (type pt) 'LIST)
(progn
(setq pt (trans pt 1 (cdr (assoc -1 e))))
(list (car pt) (cadr pt))
)
(nth pt (massoc 10 e))
)
)
)
)
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
)
)
)

--
Visit me at: http://www2.stonemedia.com/franko

"Tony Tanzillo" wrote in message
news:38D82948.DDDD884E@worldnet.att.net...
> Unfortunately, I have to advise against using the
> code Frank posted (and subsequently revised), as
> it remains bugged.
>
> My advice is to use the code I posted, mainly because
> it works, and does not fail when there's more than one
> vertex in the polyline at the same coordinate, or when
> the polyline is not in the WCS.
0 Likes
Message 12 of 14

Anonymous
Not applicable
Frank Oquendo wrote:
>
> Would you mind demonstrating this bug? The use of an index totally negates
> your assertions concerning the presence of multiple vertices at the same
> point. The same applies to your argument concerning the polyline not being
> in the WCS. That is only a factor when using a point rather than a index. If
> you're going to take the time to accuse people of writing bad code at least
> have the professional courtesy of doing your research.

You're the one who failed to do his research.
Everything you say above, is incorrect.

Given the two conditions I cited earlier, you code will
fail, regardless of whether it is passed the index of
the vertex, or its coordinate location.

I'm not here to tutor you, and I'm not going to waste
time demonstrating the bug. My comments were strictly
for the benefit of the original poster, not you. If
you don't like the fact that I choose to point out flaws
in your code, which can cause problems for those who
adopt that code, then feel free to do what you usually
do, which is to label my comments impolite, rude, or a
personal attack, and complain to Autodesk about them.

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes
Message 13 of 14

Anonymous
Not applicable
Under your tutelage, I've managed to fix every bug you've pointed out. Thank
you for your time and patience. I look forward to doing this again.

--
Visit me at: http://www2.stonemedia.com/franko
0 Likes
Message 14 of 14

Anonymous
Not applicable
P.S. You never did prove that multiple vertices could be deleted by a single
call to RV and I stand by my assertion that it isn't possible. Care to prove
otherwise?

--
Visit me at: http://www2.stonemedia.com/franko
0 Likes