Author Topic: some help for repeat loop  (Read 1495 times)

0 Members and 1 Guest are viewing this topic.

TAIKI

  • Guest
some help for repeat loop
« on: September 15, 2014, 05:08:20 PM »
Hello
Just i want help to create a repeat loop, i want to remove vertex of all polyline in a selection set.

Can you help me because i want to understand repeat loop.

Thanks


Code - Auto/Visual Lisp: [Select]
  1.  (defun c:test (/sel)
  2. (setq ent (entsel))
  3. (setq entlist (entget (car ent)))
  4. (setq layername (cdr (assoc 8 entlist)))
  5. (setq sel (ssget "x" (list (cons 8 layername) '(0 . "POLYLINE,LINE,LWPOLYLINE"))))
  6.    (repeat (setq n (sslength sel))
  7.    (acet-lwpline-remove-duplicate-pnts (ssname sel (setq n (1- n)))))
  8.      ))
  9.   (princ)
  10. )
  11. ;Takes an entity list of lwpolylines and modifies the object
  12. ;removing neighboring duplicate points. If no duplicated points
  13. ;are found then the object will not be passed to (entmod ).
  14. ;Returns the new elist when done.
  15. (defun acet-lwpline-remove-duplicate-pnts (e1 / a n lst e2)
  16.   (setq n 0)
  17.   (repeat (length e1)
  18.     (setq a (nth n e1)) ;setq
  19.     (cond
  20.       ((not (equal 10 (car a)))
  21.        (setq e2 (cons a e2))
  22.       ) ;cond #1
  23.       ((not (equal (car lst) a))
  24.        (setq lst (cons a lst)
  25.              e2  (cons a e2)
  26.        ) ;setq
  27.       ) ;cond #2
  28.     ) ;cond close
  29.     (setq n (+ n 1)) ;setq
  30.   ) ;repeat
  31.   (setq e2 (reverse e2))
  32.   (if (and e2
  33.            (not (equal e1 e2))
  34.            lst
  35.       ) ;and
  36.     (progn
  37.       (if (equal 1 (length lst))
  38.         (progn
  39.           (entdel (cdr (assoc -1 e1)))
  40.           (setq e2 nil)
  41.         ) ;progn then single vertex polyline so delete it.
  42.         (progn
  43.           (setq e2 (subst (cons 90 (length lst)) (assoc 90 e2) e2)
  44.           ) ;setq
  45.           (entmod e2)
  46.         ) ;progn else
  47.       ) ;if
  48.     ) ;progn then
  49.   ) ;if
  50.   e2
  51. )

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: some help for repeat loop
« Reply #1 on: September 16, 2014, 02:34:22 AM »
Nothing special, repeat loop repeats lines inside loop as many times as specified after repeat statement... Note that number specified for repeat function must be an integer, not floating number, or list, or string...

As for your posted code, I have one small remark...

change
Code: [Select]
(acet-lwpline-remove-duplicate-pnts (ssname sel (setq n (1- n)))))

to this
Code: [Select]
(acet-lwpline-remove-duplicate-pnts (entget (ssname sel (setq n (1- n))))))

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

TAIKI

  • Guest
Re: some help for repeat loop
« Reply #2 on: September 16, 2014, 03:03:05 PM »
Thanks for your explanation now i've understand.