Author Topic: How to reverse the linetype direction of a line or arc or polyline?  (Read 5164 times)

0 Members and 1 Guest are viewing this topic.

guohq

  • Newt
  • Posts: 84
Like the subject!

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: How to reverse the linetype direction of a line or arc or polyline?
« Reply #1 on: April 22, 2009, 01:17:14 PM »
I take it you want to write this in LISP yourself since this is the lisp forum, you are not looking for a ready made solution like the one built into AutoCAD?

With lines, I guess all you need to do is get the start and end point, erase the line, then make a new line in the reverse order. Arcs only go CCW anyway. With polylines, it's essentially the same as lines, but there are probably dozens of things to complicate the matter, including arcs, tangents, widths, whether it's a LWpoly or 3Dpoly, whether it's closed, etc.

James Cannon

  • Guest
Re: How to reverse the linetype direction of a line or arc or polyline?
« Reply #2 on: April 22, 2009, 01:27:38 PM »
What version of Autocad are you using?


guohq

  • Newt
  • Posts: 84
Re: How to reverse the linetype direction of a line or arc or polyline?
« Reply #3 on: April 23, 2009, 05:38:46 AM »
2005

Alan Cullen

  • Guest
Re: How to reverse the linetype direction of a line or arc or polyline?
« Reply #4 on: April 23, 2009, 07:21:58 AM »
Code: [Select]
;;;;;;;;;;   REVERSE POLYLINE   ;;;;;;;;;;

(defun c:rv ()
(gc) ;;garbage collection (memory)
(prompt "\nRPOLY.LSP v1.3 (c)1997, John F. Uhden, CADvantage.")

(if (< (atoi (getvar "acadver")) 12)
 (progn
  (prompt "\nSorry... Program requires AutoCAD R12 or higher.")
  (exit)
))


(setq |olderr *error*)
(defun *error* (|str)
 (setq @reset (eval @reset))
 (gc) ;;garbage collection (memory)
 (princ)
)
(setq @reset
'(progn
  (gc) ;;garbage collection (memory)
  (setq *error* |olderr |olderr nil
        @cv_main nil @cv_heavy nil @cv_light nil @ltgen nil |ltgen nil
)))

(defun @ltgen (|item / |ans)
 (cond
  ((= |ltgen 0)(setq |ans "No"))
  ((and (= (logand (cdr |item) 128) 0)(= |ltgen 1))
   (initget "Yes No")
   (setq |ans (getkword "\nTurn Linetype generation ON?  <Yes>/No: "))
  )
  (1 (setq |ans "Yes"))
 )
 (if (/= |ans "No")
  (cons 70 (logior (cdr |item) 128))
  |item
))

(defun @cv_heavy (|e / |e |e1 |ent0 |ent |ent1 |flag |bulge |new |vlist)
 (setq |e1 |e
       |ent0 (entget |e1)
       |e (entnext |e)
       |ent1 (entget |e) ; save 1st vertex for later
       |bulge (cdr (assoc 42 |ent1))
       |flag (assoc 70 |ent0)
       |e (entnext |e)
       |ent (entget |e)
 )
 (while (= (cdr (assoc 0 |ent)) "VERTEX")
  (setq |new (subst (cons 42 (- |bulge))(assoc 42 |ent) |ent)
        |bulge (cdr (assoc 42 |ent))
        |vlist (cons |new |vlist)
        |e (entnext |e)
        |ent (entget |e)
 ))
 (entmake (subst (@ltgen |flag) |flag |ent0)) ; header
 (foreach |ent |vlist (entmake |ent)) ; each vertex but first
 (entmake (subst (cons 42 (- |bulge))(assoc 42 |ent1) |ent1)) ; first vertex
 (if (entmake |ent) ; SEQEND
  (progn
   (prompt " OK")
   (entdel |e1)
   (redraw (entlast))
  )
  (prompt " Failed.")
))

(defun @cv_light (|e / |first |last |new |vlist)
 (foreach |item (reverse (entget |e))
  (cond
   ((and (not |first)(= (car |item) 10))
    (setq |first |item)
   )
   ((member (car |item) '(10 40 41))
    (setq |vlist (cons |item |vlist))
   )
   ((= (car |item) 42)
    (setq |vlist (cons (cons 42 (- (cdr |item))) |vlist))
   )
   ((= (car |item) 210)
    (setq |last |item)
   )
   ((and (= (car |item) 70)(/= |ltgen 0))
    (setq |new (cons (@ltgen |item) |new))
   )
   (1 (setq |new (cons |item |new)))
 ))
 (if (entmod (append |new (list |first)(reverse |vlist)(list |last)))
 (progn
  (prompt " OK")
  (entupd |e)
 )
 (prompt " Failed.")
))

(defun @cv_main ( / |e |etyp |ans)
 (setvar "cmdecho" 0)
 (command "_.list" "") ; dummy command for undos
 (setvar "cmdecho" 1)
 (initget "Ignore Auto On Prompt")
 (setq |ans (getkword "\nLinetype generation, Ignore/<AUto On>/Prompt when off: "))
 (cond
  ((= |ans "Ignore")(setq |ltgen 0))
  ((= |ans "Prompt")(setq |ltgen 1))
  (1 (setq |ltgen 128))
 )
 (while (setq |e (car (entsel "\nSelect a polyline: ")))
  (setq |etyp (cdr (assoc 0 (entget |e))))
  (cond
   ((= |etyp "POLYLINE")(@cv_heavy |e))
   ((= |etyp "LWPOLYLINE")(@cv_light |e))
   (1 (prompt (strcat " Entity is a(n) " |etyp)))
)))
(@cv_main)
(eval @reset)(setq @reset nil)
(princ)
)


;*******************************************************************************.
;;;;;;;;;;   REVERSE LINE   ;;;;;;;;;;

;; ----------------------------------------------------------------------
;; (Swap endpoints of a LINE object)
;; Copyright (C) 1997 DotSoft, All Rights Reserved
;; Website: www.dotsoft.com
;; ----------------------------------------------------------------------
;; DISCLAIMER: DotSoft Disclaims any and all liability for any damages
;; arising out of the use or operation, or inability to use the software.
;; FURTHERMORE, User agrees to hold DotSoft harmless from such claims.
;; DotSoft makes no warranty, either expressed or implied, as to the
;; fitness of this product for a particular purpose. All materials are
;; to be considered ‘as-is’, and use of this software should be
;; considered as AT YOUR OWN RISK.
;; ----------------------------------------------------------------------

(defun c:RL ()
(setq sset (ssget))
(setq num (sslength sset) itm 0)
(while (< itm num)
(setq hnd (ssname sset itm))
(setq ent (entget hnd))
(if (= (cdr (assoc 0 ent)) "LINE")
(progn
(setq pt1 (cdr (assoc 10 ent)))
(setq pt2 (cdr (assoc 11 ent)))
(setq ent (subst (cons 10 pt2)(assoc 10 ent) ent))
(setq ent (subst (cons 11 pt1)(assoc 11 ent) ent))
(entmod ent)
)
)
(setq itm (1+ itm))
)
(princ)
)
(prompt
"\nType RL to run command."
)

Use at your own risk......I use it every day and have had no problems. I notice some strangs symbols in there....delete them if they cause problems.

guohq

  • Newt
  • Posts: 84
Re: How to reverse the linetype direction of a line or arc or polyline?
« Reply #5 on: April 23, 2009, 09:42:37 AM »
Thank you ,I'll have a try!

James Cannon

  • Guest
Re: How to reverse the linetype direction of a line or arc or polyline?
« Reply #6 on: April 23, 2009, 09:45:07 AM »
2005

just checking.

2010 has this as a core feature now, apparently.

guohq

  • Newt
  • Posts: 84
Re: How to reverse the linetype direction of a line or arc or polyline?
« Reply #7 on: April 24, 2009, 01:22:28 AM »
If it is a ellipse , I can drag one quadrant to anthor ,then the linetype direction will be reversed.  how to do this by program not by manual.

rkmcswain

  • Swamp Rat
  • Posts: 978

2010 has this as a core feature now, apparently.

It was originally included starting with 2009, Bonus Pack 1.

curmudgeon

  • Newt
  • Posts: 194
kind of busy here, but I have been working with lwpolylines on this project where I needed to check rotation for a closed figure.

I worked with a list I strip from the entity data, just the vertexes. I had wanted the centroid, but in the process of finding the centroid, there was a summation that I also needed that gave the area of the figure.

lo, and behold, at whiles this algorithm produces a negative area!

I find that I this is dependent upon rotation. I think I am remembering that a positive value for area is CCW rotation for a closed LWPOLYLINE, and a negative of course means CW rotation. then, gile showed me the REVERSE function - so I can (< 0 area_variable ) to check rotation, and reverse if I don't like the results of the test.

I thought that was pretty cool. but I am easily impressed sometimes.

too busy to post at this instant, and it is probably redundant here, but if anybody wants it I can find it.
Never express yourself more clearly than you are able to think.