Author Topic: Reverse Polyline/Arc  (Read 7629 times)

0 Members and 1 Guest are viewing this topic.

PHX cadie

  • Water Moccasin
  • Posts: 1891
Reverse Polyline/Arc
« on: September 25, 2006, 11:50:30 AM »
We often have linetypes with text to denote the type of utilities and when I came across a base dwg from a sub I was going to quickly reverse it so the text included in the lt read from the right. We have the lisp below to reverse a pline, but now I get an error message "not a closed polyline".

Code: [Select]
  ;; REVPOLY.LSP
;; Reverts order of vertices of a selected (not closed) polyline.
;; Supports bulge, different widthes of the polyline segments,
;; FITted and SPLINEd polylines
;; 15.04.97  S.Komarov

(defun C:REVPOLY (/ pl pln cass i ent vlist blist swl ewl)
 (defun CASS (cod ent)
  (cdr(assoc cod (entget ent)))
 )
 (setq pl (entsel "Select polyline:"))
 (if pl
 (progn
 (setq pl (car pl))
 (if (and (equal "POLYLINE" (cass 0 pl))
          (/= 1 (cass 70 pl)))
 (progn
 (setq pln pl i 0)
 (while (not (= "SEQEND" (cass 0 (setq pln (entnext pln)))))
        (setq blist (cons (cass 42 pln) blist)
              vlist (cons (entget pln) vlist)
              swl (cons (cass 40 pln) swl)
              ewl (cons (cass 41 pln) ewl)
              i  (1+ i)
        )
 )
 (setq blist (append (cdr blist)(list (car blist)))
       blist (mapcar '(lambda (x) (- 0 x)) blist)
         swl (append (cdr swl)(list (last swl)))
         ewl (append (cdr ewl)(list (last swl)))
           i 0 pln pl
 )
 (setq ent (cdr (entget pln))
       ent (subst (cons 40 (car ewl))(assoc 40 ent) ent)
       ent (subst (cons 41 (last swl))(assoc 41 ent) ent)
 )
 (entmake ent) ; polyline
 (while (not (= "SEQEND" (cass 0 (setq pln (entnext pln)))))
     (progn
     (setq ent (nth i vlist)
           ent (subst (cons 40 (nth i ewl))(assoc 40 ent) ent)
           ent (subst (cons 41 (nth i swl))(assoc 41 ent) ent)
           ent (subst (cons 42 (nth i blist))(assoc 42 ent) ent)
           i (1+ i)
     )
     (entmake ent)
 ))
 (entmake (cdr (entget pln))); seqend
 (entdel pl)(redraw(entlast))
 (princ "\nDone!")
 )
 (prompt "\nNot a polyline or closed polyline")
 )
)
(prompt "\nNothing selected!")
)
(princ)
)
(prompt "\nProgram loaded. Call by REVPOLY")(princ)
  )
[/quote]

Even if the lisp worked, the 2 lines I was going to correct are Arcs. No matter which endpoint I started to re draw the arc, the text was the same direction (opposite the way I wanted).
To end this long sob story:

1.  Does anyone have a lisp to reverse the direction of a pline? (to push my luck will it work on arcs?)

If anyone feels like typing, I'm curious:
2. What dictates the alignment of text (in a LT) when drawing an arc?

Tanks  :-)
Acad 2013 and XM
Back when High Tech meant you had an adjustable triangle

CAB

  • Global Moderator
  • Seagull
  • Posts: 10369
Re: Reverse Polyline/Arc
« Reply #1 on: September 25, 2006, 01:15:27 PM »
This will reverse a LWpolyline:
http://www.theswamp.org/index.php?topic=8878.msg114590#msg114590
The routine you have is good for Oldstyle,"Heavy Polylines".

As for the ARC, there is no way to reverse it. Even arcs within plines.

You could convert the arcs to segmented straight plines but that may not give you the results you are looking for as the segment length may be too short for the line type.

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.

rkmcswain

  • Swamp Rat
  • Posts: 949
Re: Reverse Polyline/Arc
« Reply #2 on: September 25, 2006, 01:24:20 PM »

As for the ARC, there is no way to reverse it. Even arcs within plines.


Not true, if the intent is to display the linetype consistnently throughout the polyline.
As long as LTGEN is enabled, the linetype will follow the "direction" of the polyline, ARCs included.

PHX cadie

  • Water Moccasin
  • Posts: 1891
Re: Reverse Polyline/Arc
« Reply #3 on: September 25, 2006, 01:52:53 PM »
I did run across that thread.
 Not being a "Code Talker", (think Nicolas Cage would do a sequel? ?) I didn't understand the dif between the 2 codes, (will exp during lunch) plus I wanted to greedy and see if it was poss w/ arcs.

Thanks All
Acad 2013 and XM
Back when High Tech meant you had an adjustable triangle

CAB

  • Global Moderator
  • Seagull
  • Posts: 10369
Re: Reverse Polyline/Arc
« Reply #4 on: September 25, 2006, 01:58:39 PM »
Rick, Right you are. I had forgotten about that setting.
I was able to reverse a pline arc with a text linetype and as long as the "Linetype Generation" property is enabled it displayed properly. :-)

So the fix for PHX cadie is to create pline arcs & delete the ARCs.
Enable the "Linetype Generation" property
Change the line type to that desired
Reverse the pline if needed.
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.

gile

  • Water Moccasin
  • Posts: 2233
  • Marseille, France
Re: Reverse Polyline/Arc
« Reply #5 on: September 26, 2006, 05:00:44 PM »
Hi,

Here's another one.
It works with lwpolylines, old-style 2d polylines, and 3d polylines, open or closed and keep all properties (arcs width ...)

Code: [Select]
(defun reverse_pline (ent / e_lst vtx v_lst p_lst l_vtx)
  (setq e_lst (entget ent))
  (cond
    ((= (cdr (assoc 0 e_lst)) "POLYLINE")
     (setq vtx (entnext ent))
     (while (= (cdr (assoc 0 (entget vtx))) "VERTEX")
       (setq v_lst (cons (entget vtx) v_lst)
     vtx   (entnext vtx)
       )
     )
    )
    ((= (cdr (assoc 0 e_lst)) "LWPOLYLINE")
     (setq p_lst (vl-remove-if-not
   '(lambda (x)
      (member (car x) '(10 40 41 42))
    )
   e_lst
)
   e_lst (vl-remove-if
   '(lambda (x)
      (member x p_lst)
    )
   e_lst
)
     )
     (while p_lst
       (setq v_lst (cons
     (list (car p_lst) (cadr p_lst) (caddr p_lst) (cadddr p_lst))
     v_lst
   )
     p_lst (member (assoc 10 (cdr p_lst)) (cdr p_lst))
       )
     )
    )
  )
  (setq l_vtx (last v_lst)
l_vtx (subst (cons 40 (cdr (assoc 41 (car v_lst))))
     (assoc 40 l_vtx)
     l_vtx
      )
l_vtx (subst (cons 41 (cdr (assoc 40 (car v_lst))))
     (assoc 41 l_vtx)
     l_vtx
      )
l_vtx (subst (cons 42 (- (cdr (assoc 42 (car v_lst)))))
     (assoc 42 l_vtx)
     l_vtx
      )
  )
  (setq v_lst
(mapcar
   '(lambda (x y)
      (setq x (subst (cons 40 (cdr (assoc 41 y))) (assoc 40 x) x)
    x (subst (cons 41 (cdr (assoc 40 y))) (assoc 41 x) x)
    x (subst (cons 42 (- (cdr (assoc 42 y)))) (assoc 42 x) x)
      )
    )
   v_lst
   (cdr v_lst)
)
  )
  (if (= (logand 1 (cdr (assoc 70 e_lst))) 1)
    (setq v_lst (append (list l_vtx) v_lst))
    (setq v_lst (append v_lst (list l_vtx)))
  )
  (cond
    ((= (cdr (assoc 0 e_lst)) "POLYLINE")
     (mapcar 'entmake
     (append (list e_lst) v_lst (list (entget vtx)))
     )
     (entdel ent)
    )
    ((= (cdr (assoc 0 e_lst)) "LWPOLYLINE")
     (setq e_lst (append e_lst (apply 'append v_lst)))
     (entmod e_lst)
    )
  )
)


(defun c:r_pline (/ ent)
  (while (not (setq ent (car (entsel)))))
  (if (or (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
  (and (= (cdr (assoc 0 (entget ent))) "POLYLINE")
       (zerop (logand 240 (cdr (assoc 70 (entget ent)))))
  )
      )
    (reverse_pline ent)
    (prompt "\nEntit non valide")
  )
  (princ)
)
Speaking English as a French Frog

CAB

  • Global Moderator
  • Seagull
  • Posts: 10369
Re: Reverse Polyline/Arc
« Reply #6 on: May 06, 2007, 10:30:39 AM »
I was just revisiting this topic and created a lisp to fix a problem displaying some line types
if the system variable PLINEGEN is set to 0.

The fix is to set the DXF code 70  bit 128. Here is a routine to do just that.
Code: [Select]
;;  CAB 05.06.07
;;  Set the PlineGen bit in DXF 70 so the complex line
;;  will display properly on arcs, note that the pline may
;;  need to be reversed after this fix
(defun c:PlineFixText(/ ss lst elst ent dxf70)
  (and
    (princ "\nSelect polylines to fix.")
    (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE"))))
    (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
    (foreach ent lst
      (setq elst (entget ent))
      (if (zerop (logand 128 (cdr (assoc 70 elst))))
        (progn
          (setq dxf70 (assoc 70 elst)
                elst (subst (cons 70 (+ 128 (cdr dxf70))) dxf70 elst))
          (entmod elst)
        )
      )
    )
  )
  (princ)
)
(prompt "\nPline Text Fix loaded, Enter PlineFixText to run.")
(princ)

<edit: added picture>
« Last Edit: May 06, 2007, 10:34:25 AM by CAB »
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.

chlh_jd

  • Guest
Re: Reverse Polyline/Arc
« Reply #7 on: January 16, 2011, 03:43:46 AM »
The following code can flip the arrow
Code: [Select]
;;GSLS(SS) 2010-07-11
(defun ss-reverse-pl (en / ent pl_vetex b is fst est lst n)
  (setq ent (entget en '("*")))
  (setq pl_vetex nil
b nil
is T
fst nil
est nil
  )
  (foreach n ent ;_(setq e (assoc 10 ent))
    (if (= (car n) 210)
      (setq is nil)
    )
    (cond ((and (or (= 10 (car n))
    (= 40 (car n))
    (= 41 (car n))
    (= 42 (car n))
)
is
   )
   (setq b (cons (cdr n) b))
   (if (= 4 (length b))
     (setq pl_vetex (append pl_vetex (list b))
     b
     nil
   )
  )
    )
    (is
      (setq fst (cons n fst))
    )
    (T (setq est (cons n est)))
  ))
  (setq lst nil)
  (foreach a pl_vetex
    (setq lst (append (list (cons 10 (cadddr a))
    (cons 40 (caddr a))
    (cons 41 (cadr a))
    (cons 42 (* -1.0 (car a)))
      )
      lst
      )
    )
  )
  (setq lst (append (reverse fst)
    lst
    (reverse est)
    )
  )
  (setq ent lst)
  (entmod ent)
)