Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reversing Arced polylines

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
189 Views, 4 Replies

Reversing Arced polylines

Hello, I have always had difficulty reversing (programmatically in Lisp) the direction of a polyline that has arc segments in them. Does anyone have a code that would reverse arc segmented polylines? I got around it with a tip that was posted here some years back. It involves drawing a line from the center of the current view to the end point of the polyline and then using the Pedit Join command to select this line and the original polyline. This would reverse arced polylines. Then the first vertex of the polyline had to be deleted. This method, however fails when if the polyline is closed and if the last segment happens to be an arc. In such a case, the above method would reverse the polyline but the last arced segment becomes a straight line. So, I am now looking for a more robust solution to this. I am not very good to playing with the bulge factors. Any pointers, code welcome. Regards Rakesh -- Please email me your replies. I may not always be observing the posts here. email: rakesh.rao@4d-technologies.com AutoCAD customization for Engineering/Mapping/GIS Get GeoTools @ http://www.4d-technologies.com/geotools Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm FREE downloads : http://www.4d-technologies.com/techcenter
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Hi only a short idea: If there is an arc, so get 3 points of it using the DIVIDE-command. In order to reverse create the reverse arc from these 3 point in reverse order (I don't like the bulges and chords too...). Regards Jochen www.black-cad.de "Rakesh Rao" schrieb im Newsbeitrag news:407287A0.3080709@4d-technologies.com... > > Hello, > > I have always had difficulty reversing (programmatically in Lisp) the > direction of a polyline that has arc segments in them. Does anyone have > a code that would reverse arc segmented polylines? > > I got around it with a tip that was posted here some years back. It > involves drawing a line from the center of the current view to the end > point of the polyline and then using the Pedit Join command to select > this line and the original polyline. This would reverse arced polylines. > Then the first vertex of the polyline had to be deleted. > > This method, however fails when if the polyline is closed and if the > last segment happens to be an arc. In such a case, the above method > would reverse the polyline but the last arced segment becomes a straight > line. So, I am now looking for a more robust solution to this. I am not > very good to playing with the bulge factors. > > Any pointers, code welcome. > > Regards > Rakesh > -- > > Please email me your replies. I may not always be observing the posts here. > > email: rakesh.rao@4d-technologies.com > > AutoCAD customization for Engineering/Mapping/GIS > Get GeoTools @ http://www.4d-technologies.com/geotools > Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm > FREE downloads : http://www.4d-technologies.com/techcenter > >
Message 3 of 5
Anonymous
in reply to: Anonymous

Check your email. regards, Tim Badger "Rakesh Rao" wrote in message news:407287A0.3080709@4d-technologies.com... > > Hello, > > I have always had difficulty reversing (programmatically in Lisp) the > direction of a polyline that has arc segments in them. Does anyone have > a code that would reverse arc segmented polylines? > > I got around it with a tip that was posted here some years back. It > involves drawing a line from the center of the current view to the end > point of the polyline and then using the Pedit Join command to select > this line and the original polyline. This would reverse arced polylines. > Then the first vertex of the polyline had to be deleted. > > This method, however fails when if the polyline is closed and if the > last segment happens to be an arc. In such a case, the above method > would reverse the polyline but the last arced segment becomes a straight > line. So, I am now looking for a more robust solution to this. I am not > very good to playing with the bulge factors. > > Any pointers, code welcome. > > Regards > Rakesh > -- > > Please email me your replies. I may not always be observing the posts here. > > email: rakesh.rao@4d-technologies.com > > AutoCAD customization for Engineering/Mapping/GIS > Get GeoTools @ http://www.4d-technologies.com/geotools > Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm > FREE downloads : http://www.4d-technologies.com/techcenter > >
Message 4 of 5
Anonymous
in reply to: Anonymous

"Rakesh Rao", It's actually rather simple. You just have to remember that in DXF form the bulge factor stays in between the two points defining the start and end of the arc. It simply defines the bulge of the arc between the two points. When reversing the pline data just reverse the point and bulge list, then use the sign of the original bulge, ie: (- 0.0 bulge). In dxf format it's (note this is using my list format which varies slightly, you may have to switch cadr's for cdr's and vise-versa)... (setq data (mapcar '(lambda (a) (cond ((= (car a) 10) a);strip all but points and bulges ((= (car a) 42) (ccons 42 (sign (cadr a)))) ) ) (reverse data) ) ) (if (= (car (car data)) 42);move arc data to end if it's first element (setq data (append (cdr data) (list (car data)))) )
Message 5 of 5
cab2k
in reply to: Anonymous

;;; Polyline Reverse
;;; plr.lsp by Charles Alan Butler
;;; Copyright 2004
;;; by Precision Drafting & Design All Rights Reserved.
;;; Contact at ab2draft@TampaBay.rr.com
;;;
;;; Version Alpha March 20,2004
;;;
;;; Reverse the vertex order of a light weight polyline
;;; Keeps the same starting point unlike most reverse routines
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;; ;
;;; You are hereby granted permission to use, copy and modify this ;
;;; software without charge, provided you do so exclusively for ;
;;; your own use or for use by others in your organization in the ;
;;; performance of their normal duties, and provided further that ;
;;; the above copyright notice appears in all copies and both that ;
;;; copyright notice and the limited warranty and restricted rights ;
;;; notice below appear in all supporting documentation. ;
;;;
(defun c:plr (/ elst vlst newlst new-vlst code42 code210
obj nam pair clo)
(command "_.undo" "_be")
(while (null (setq en1 (entsel "\nPick an object to reverse: "))))
(setq nam (car en1)
elst (entget nam)
obj (cdr (assoc 0 elst))
clo (= 1 (logand 1 (cdr (assoc 70 (entget nam)))))
)
(cond
((= obj "LWPOLYLINE")
(setq new-vlst (list (assoc 10 elst))) ; start point
(while (setq pair (car elst))
(cond
((= (car pair) 10) ; vertex
;; collect vertex list
(while (member (caar elst) '(10 40 41 42))
(setq vlst (cons (car elst) vlst)
elst (cdr elst))
) ; end while
)
((= (car pair) 210) ; extru direction??
(setq code210 pair
elst (cdr elst))
)
((setq newlst (cons pair newlst)
elst (cdr elst))
)
) ; end cond stmt
) ; end while
;; newlst= entlist less vertex list
;; vlst= vertex list
(while vlst ; reverse vertex list
(if (= (car (setq pair (car vlst))) 42) ; bulge
;; reverse the bulge
(setq code42 (cons 42 (* (cdr pair) -1))
vlst (cdr vlst))
)
(if (= (car (setq pair (car vlst))) 41)
;; reverse the width position
(setq vlst (cdr vlst)
new-vlst (cons (cons 40 (cdr pair)) new-vlst)
new-vlst (cons (cons 41 (cdr (car vlst))) new-vlst)
vlst (cdr vlst))
)
(if code42 ; add bulge back to list
(setq new-vlst (cons code42 new-vlst)
code42 nil)
)
(if (= (car (setq pair (car vlst))) 10)
(setq new-vlst (cons pair new-vlst)
vlst (cdr vlst))
)
) ; end while
(if clo ; closed pline
(setq new-vlst (cdr new-vlst)) ; remove the start pt
(setq new-vlst (reverse(cdr (reverse new-vlst))))
)
;; new-vlst contains the reverse vertex list
(setq newlst (append new-vlst newlst))
(if code210
(setq newlst (append (list code210) newlst))
)
(entmod (reverse newlst))
(entupd nam) ; Regenerates the polyline entity
)

((= obj "POLYLINE")
(prompt "\nNot yet working... Old Style Polyline."))

((prompt "\nObject selected is not a polyline"))
) ; end cond stmt
(princ)
) ; end defun

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost