;  Subject:      Re: invert the direction of a polyline
;  From:         vnestr@netvision.net.il (Vladimir Nesterovsky)
;  Date:         1997/03/01
;  Newsgroups:   comp.cad.autocad
;
;  Try this:

   ;; This is (C.) by Vladimir Nesterovsky, 1997
   ;; e-mail: vnestr@netvision.net.il
   ;; YOU MAY USE THIS CODE ONLY FOR *NON-COMMERCIAL*
   ;; PURPOSES AND ONLY IF YOU RETAIN
   ;; THIS HEADER COMPLETE AND UNALTERED
   ;; you must contact me if you want to use it commercially
   (defun c:invpl( )
    (r-ss-foreach
      (ssget '((0 . "POLYLINE")))
      'inv-pl)
    (princ"\nInverted!")
    (princ))

   ;; repeat (foo e-name) for each e-name in SelSet
   ;; in reversed order
   (defun r-ss-foreach ( ss qfoo / n )
    (if (= 'PICKSET (type ss))
     (repeat (setq n (fix (sslength ss))) ;; a little fix
      (apply qfoo (list (ssname ss (setq n (1- n))))))))

   (defun dxf(a b)(cdr(assoc a b)))

   ;;Invert polyline
   (defun inv-pl( e / d0 di d bl pl swl ewl )
     (setq d0 (entget e '("*"))) ;; keep xdata
     (while (/= "SEQEND" (dxf 0 (setq di
              (entget (setq e (entnext e))))))
       (setq  d di
             pl (cons (dxf 10 d) pl)
            swl (cons (dxf 40 d) swl)
            ewl (cons (dxf 41 d) ewl)
             bl (cons (-(dxf 42 d)) bl) ))
     (setq  ;; cycle the lists
           bl  (append (cdr  bl) (list (car  bl)))
           swl (append (cdr swl) (list (car swl)))
           ewl (append (cdr ewl) (list (car ewl))) )

     (entmake d0)
     (mapcar
      '(lambda(p b sw ew)(entmake
        (subst (cons 10 p)(assoc 10 d)
         (subst (cons 42 b)(assoc 42 d)
          (subst (cons 40 sw)(assoc 40 d)
           (subst (cons 41 ew)(assoc 41 d)
             d))))))
       pl bl ewl swl)
     (entmake(list '(0 . "SEQEND")(cons 8 (dxf 8 d0))))
     (entdel (dxf -1 d0))
     (redraw (entlast))
     (princ)
   )

;  You can alter this code to carry vertex widths also,
;  if you care.
;
;  ------- Original message: -------
;  On 21 Feb 1997 11:15:00 GMT,  - "Decurtins Reto"  wrote
;  in comp.cad.autocad:
;
;  Is this possible and how ?


;;; Changes:
;;; 1997/11/06: slight improvements:
;;;                inv-pl to carry width info and keep EED