View Full Version : Reversing Polylines
Wiggy
1st Aug 2006, 11:01 am
Hello there.
I work for an Underground Surveying company, and we've got a bit of an annoyance that we can't seem to work out.
We use polylines to represent Ultilities ie. Water, Gas, etc
The Linetype Control therefore says ----Gas----Gas----, which is fine, however. when we download the raw DXF from our equipment and change the polylines to our layers, sometimes the ----Gas----Gas---- is shown upside down.
Now we know why this happens (it's not really relavant here), but we were wondering if there is a way to flip them over without having to re-draw over them. Because on big, or complex drawings it's quite time consuming.
I don't really think there is a way to do it, but if any of you experts could suggest anything I'd be most grateful.
If ya need a picture to explain what I mean then just shout. Cheers. :)
Oh, we use LT 2002 and 2006.
daiharv
1st Aug 2006, 12:09 pm
Here's a lsp routine that reverses polylines. This can easily loaded through 2006 full and if you download LT-Extender you can load it through LT also.
;;; RPL.LSP a program to reverse the direction of polylines
;;; Program by Tony Hotchkiss. Enter RPL to start the program.
(prompt
"\nType RPL to run command."
)
(defun c:rpl ()
(setq again nil)
(setq p-ent nil)
(prompt "\nSelect a polyline: ")
(while (not p-ent)
(setq p-ent (car (entsel)))
(if (not p-ent)
(prompt
"\nNo object selected; select again: "
) ;_ end of prompt
(progn
(if (and (/= (dxf 0 p-ent) "POLYLINE")
(/= (dxf 0 p-ent) "LWPOLYLINE")
) ;_ end of and
(progn
(prompt "\nNot a polyline, select again:"
) ;_ end of prompt
(setq p-ent nil)
) ; progn
) ;_ end of if
) ;_ end of progn
) ;_ end of if
) ;_ end of while
(setq etype (dxf 0 p-ent)
x-ent p-ent
is-closed (dxf 70 p-ent)
) ; setq
(if (= etype "LWPOLYLINE")
(progn
(setq num-vert (dxf 90 p-ent)
elist (entget p-ent)
elist (member (assoc 10 elist) elist)
vvlist nil
) ; setq
(repeat num-vert
(setq vlist (list (cdr (assoc 10 elist))))
(setq vlist
(append vlist
(list (cdr (assoc 42 elist)))
) ;_ end of append
) ;_ end of setq
(setq vvlist (append vvlist
(list vlist)
) ;_ end of append
) ;_ end of setq
(setq elist (cdr elist)
elist (member (assoc 10 elist) elist)
) ; setq
) ; repeat
) ; progn lwpolyline
(progn
(setq vvlist nil
p-ent (entnext p-ent)
) ; setq
(while (/= "SEQEND"
(cdr
(assoc 0 (entget p-ent))
) ;_ end of cdr
) ;_ end of /=
(setq vlist (list (dxf 10 p-ent)))
(setq vlist (append vlist
(list (dxf 42 p-ent))
) ;_ end of append
) ;_ end of setq
(setq vvlist (append vvlist
(list vlist)
) ;_ end of append
) ;_ end of setq
(setq p-ent (entnext p-ent))
) ; while
) ; progn polyline
) ; if
(setq p-list (mapcar 'car vvlist)
p-list (reverse p-list)
b-list (mapcar 'cadr vvlist)
b-list (reverse b-list)
b-first (car b-list)
b-list (cdr b-list)
b-list (append b-list (list b-first))
b-list (mapcar '- b-list)
) ; setq
(setq enlist (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(cons 90 (length p-list))
(cons 70 (dxf 70 x-ent))
(cons 8 (dxf 8 x-ent))
) ; list
) ; setq
(setq elst nil)
(repeat (length p-list)
(setq
elst (append elst
(list (cons 10 (car p-list)))
) ;_ end of append
) ; setq
(setq
elst (append elst
(list (cons 42 (car b-list)))
) ;_ end of append
) ; setq
(setq p-list (cdr p-list))
(setq b-list (cdr b-list))
) ; repeat
(setq enlist (append enlist elst))
(entdel x-ent)
(entmake enlist)
(prompt "\nPolyline direction is reversed.\n ")
(princ)
) ; rpl
(defun dxf (code ename)
(cdr (assoc code (entget ename)))
) ;_ end of dxf
here's a lsp for reversing a line also
; ----------------------------------------------------------------------
; (Swap endpoints of a LINE object)
; Copyright (C) 1997 DotSoft, All Rights Reserved
; Website: www.dotsoft.com (http://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."
)
profcad
1st Aug 2006, 12:46 pm
You could also create a new complex linetype where the text is rotated 180°. You would have to create one for each individual linetype.
I tried it with the gas line and this is what I had to do to get them to look the same. Changes are in Red.
Use properties and change the linetype of all the gas lines that are backwards.
GAS_LINE,Gas line ----GAS----GAS----GAS----GAS----GAS----GAS--
A,.5,-.2,["GAS",STANDARD,S=.1,R=0.0,X=-0.1,Y=-.05],-.25
*GAS_LINE180,Gas line ----GAS----GAS----GAS----GAS----GAS----GAS--
A,.5,-.2,["GAS",STANDARD,S=.1,R=180.0,X=0.15,Y=.05],-.25
I would recommend using the LISP routine that daiharv uploaded, if at all possible.
This will work with LT with out having to use LISP.
Wiggy
1st Aug 2006, 01:17 pm
Wow, thanks very much fellas.
That's very kind of you.
You couldn't be more helpful. :shock: :)
tharney
7th Sep 2007, 02:23 pm
How do I go a bout loading that lisp command? Can I copy / paste that code somewhere?
PS_Port
7th Sep 2007, 02:29 pm
tharney, check this out http://www.cadtutor.net/forum/showthread.php?t=2791&highlight=loading+lisp
brassworks
10th Sep 2007, 01:56 pm
Sometimes when I run into the same upside-down text-within-line problem, I explode the polyline, rotate one of the line segments 180, and then, using that rotated line segment as the line to which all the other segments will be joined, recreate the polyline. We also have some of our text-labeled linetypes set up 180 degrees, but I don't use them often.
But anybody dealing with a lot of polylines that need to have their text flipped will undoubtedly find that using a lsp routine with a couple of command line and keyboard clicks a very efficient solution.
ChrisCMU
15th Jul 2008, 08:07 pm
That first lisp works great daiharv, thanks! The only negative I see is that it resets the linetype back to "bylayer" but it's a lot easier to change the type than mess with reversing it manually.
This saves me a lot of time (mine is a linetype symbol that is only along one side of the line, and sometimes the wrong side).
Powered by vBulletin™ Version 4.1.2 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.