### Author Topic: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint  (Read 602 times)

0 Members and 1 Guest are viewing this topic.

#### Marc'Antonio Alessi

• Swamp Rat
• Posts: 1079
• Marco
##### Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
« on: October 22, 2018, 12:54:02 PM »
Is this a good solution?
Code: [Select]
`(defun Ale_Pline_LwVertices (EntObj FuzFac / LstVrt VrtIdx VrtInf OutLst) ; EntObj = VLA-OBJECT or ENAME   (setq    VrtIdx (vlax-curve-getEndParam EntObj)    LstVrt (vlax-curve-getPointAtParam EntObj VrtIdx)  )            (while (> VrtIdx 0)    (setq VrtInf (vlax-curve-getPointAtParam EntObj (setq VrtIdx (1- VrtIdx))))    (or (equal (car OutLst) VrtInf FuzFac) (setq OutLst (cons VrtInf OutLst)))  )  (if OutLst (if (equal LstVrt VrtInf FuzFac) OutLst (append OutLst (list LstVrt)))))`

#### CAB

• Global Moderator
• Seagull
• Posts: 10388
##### Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
« Reply #1 on: October 22, 2018, 01:57:02 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970

#### Dlanor

• Bull Frog
• Posts: 260
##### Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
« Reply #2 on: October 22, 2018, 02:14:53 PM »
My 2 cents

Code - Auto/Visual Lisp: [Select]
1. ; requires coords as a list of lists
2. (defun del_dups ( lst / item n_lst)
3.   (while (> (length lst) 1)
4.     (setq item (car lst)
5.           n_lst (cons (car lst) n_lst)
6.           lst (vl-remove item (cdr lst))
7.     );end_setq
8.   );end_while
9.   (if (= (length lst) 1) (setq n_lst (cons (car lst) n_lst)))
10.   (reverse n_lst)
11. );end_defun
12.

#### Marc'Antonio Alessi

• Swamp Rat
• Posts: 1079
• Marco
##### Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
« Reply #3 on: October 23, 2018, 02:16:59 AM »
Thanks to all.

@CAB: I know that topic but I needed a simpler and faster solution.

My scenario:
- polyline A with overlapped vertex or startpoint "near" or equal to endpoint
- make a new polyline B from polyline A
- make a region from polyline B

(or (eq :vlax-true (vla-get-closed LwPObj)) (vla-Put-Closed LwPObj :vlax-True))
(setq RegObj (vlax-invoke *AcMdSpc* 'addregion (list LwPObj)))

Problem: if polyline A is not "clean" the region is not created.

#### Dlanor

• Bull Frog
• Posts: 260
##### Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
« Reply #4 on: October 23, 2018, 04:41:24 AM »
This may help, post 2 by Kent Cooper, a routine to find self crossing polylines

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/to-find-self-intersection-of-lwpolyline/td-p/6490654