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
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
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Dlanor

  • Bull Frog
  • Posts: 260
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.  

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1079
  • Marco
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.

Dlanor

  • Bull Frog
  • Posts: 260