 ; Tf - flip the first three segments of a tag leader polyline.
 ; Copyright 2012 by Rocket Software Ltd.
 ; 
 (DEFUN C:TF (/ enam entt esav typp sub ptlis angg p1 p2 p3 p4 disa)
  (setvar "cmdecho" 0)
  (setq enam (car (entsel "Tag Leader: ")))
  (setq entt (entget enam))
  (setq typp (cdr (assoc 0 entt)))
  (cond ((= typp "LWPOLYLINE")
         (setq esav entt)
         (while (and (< (length ptlis) 4)
                     entt)
                 (while (and entt
                             (/= (car (setq sub (car entt))) 10))
                        (setq entt (cdr entt)))
                 (if (= (car sub) 10)
                     (progn
                          (setq ptlis (cons sub ptlis))
                          (setq entt (cdr entt)))))
         (setq ptlis (reverse ptlis))
         (if (and (= (length ptlis) 4)
                  (= (setq angg (angle (setq p2 (cdadr ptlis))
                                       (setq p1 (cdar ptlis))))
                     (angle (setq p3 (cdaddr ptlis))
                            (setq p4 (cdr (cadddr ptlis)))))
                  (= (setq disa (distance p1 p2)) (distance p3 p4)))
             (progn
                  (setq p2a (polar p1 angg disa))
                  (setq p3a (polar p4 angg disa))
                  (setq esav (subst (cons 10 p2a) (cons 10 p2) esav))
;                 (grdraw p1 p4 6)
;                 (grdraw p2a p3a 3)
                  (entmod (subst (cons 10 p3a) (cons 10 p3) esav)))
             (prompt "\nThat dint look like no wire tag line to me.")))
        ((= typp "POLYLINE")
         (setq esav enam)
         (while (and (< (length ptlis) 4)
                     (/= "SEQEND" (cdr (assoc 0 (setq entt (entget
                                              (setq enam (entnext enam))))))))
                (setq ptlis (cons (list (cdr (assoc 10 entt)) enam) ptlis)))
         (setq ptlis (reverse ptlis))
         (if (and (= (length ptlis) 4)
                  (= (setq angg (angle (setq p2 (car (nth 1 ptlis)))
                                       (setq p1 (car (nth 0 ptlis)))))
                     (angle (setq p3 (car (nth 2 ptlis)))
                            (setq p4 (car (nth 3 ptlis)))))
                  (= (setq disa (distance p1 p2)) (distance p3 p4)))
             (progn
                  (setq p2a (polar p1 angg disa))
                  (setq entt (entget (cadr (nth 1 ptlis))))
                  (entmod (subst (cons 10 p2a) (assoc 10 entt) entt))
                  (setq p3a (polar p4 angg disa))
;                 (grdraw p1 p4 6)
;                 (grdraw p2a p3a 3)
                  (setq entt (entget (cadr (nth 2 ptlis))))
                  (entmod (subst (cons 10 p3a) (assoc 10 entt) entt))
                  (entupd esav))
             (prompt "\nThat dint look like no wire tag line to me."))))
 (princ))