TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Marc'Antonio Alessi on October 22, 2018, 12:54:02 PM

Title: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
Post by: Marc'Antonio Alessi 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))))
)
Title: Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
Post by: CAB on October 22, 2018, 01:57:02 PM
Old topic but may be of interest.
http://www.theswamp.org/index.php?topic=19865.msg244892#msg244892 (http://www.theswamp.org/index.php?topic=19865.msg244892#msg244892)
Title: Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
Post by: Dlanor on October 22, 2018, 02:14:53 PM
My 2 cents  :crazy2: :crazy2:

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.  
Title: Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
Post by: Marc'Antonio Alessi 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

(setq LwPObj (vla-AddLightweightPolyline *AcMdSpc* CoordList)
(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.
Title: Re: Remove equal polyline vertex from list, especially the same StartPoint-EndPoint
Post by: Dlanor 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 (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/to-find-self-intersection-of-lwpolyline/td-p/6490654)