works like a charm T. Willey. And it handles curves.
a shorter key in command and a built-in reverse polyline direction option (Yes/No) would be make it almost perfect.
You can change the calling command, just change this line
(defun c:ReOrderPoly (.......)
the 'c:ReOrderPoly' part.
Reversing, not sure about that one, but if I get some spare time I can look into it.
You're welcome. Here is an even better version, if the pline should be closed, but isn't, it wouldn't draw it correctly, so now it will close it if it should be. Thanks Tim2 for pointing it out 'Tim Creary'.
(defun c:ReOrderPoly (/ Sel Pt Pobj EntData Ptype PtList VertexPt PtListIndex StWd EndWd PolyList OldIndex StPos cnt
tmpList ShouldClose)
(vl-load-com)
(defun ChangeOldStyle (Ent Pt / Pent cnt EntData PolyInfoList StPos StPt ShouldClose)
(setq Pent Ent)
(setq cnt 0)
(while
(and
(setq Ent (entnext Ent))
(setq EntData (entget Ent))
(= (cdr (assoc 0 EntData)) "VERTEX")
)
(setq PolyInfoList
(cons
(list
cnt
(cdr (assoc 10 EntData))
(cdr (assoc 42 EntData))
(cdr (assoc 40 EntData))
(cdr (assoc 41 EntData))
)
PolyInfoList
)
)
(if (equal cnt 0)
(setq StPt (cdr (assoc 10 EntData)))
)
(setq cnt (1+ cnt))
(setq ShouldClose (equal StPt (cdr (assoc 10 EntData)) 0.0001))
)
(foreach Lst PolyInfoList
(if (equal Pt (cadr Lst))
(setq OldIndex (car Lst))
)
)
(setq PolyInfoList (reverse PolyInfoList))
(setq StPos (vl-position (assoc OldIndex PolyInfoList) PolyInfoList))
(setq cnt StPos)
(setq Ent Pent)
(while
(and
(setq Ent (entnext Ent))
(setq EntData (entget Ent))
(= (cdr (assoc 0 EntData)) "VERTEX")
)
(setq EntData (subst (cons 10 (cadr (nth cnt PolyInfoList))) (assoc 10 EntData) EntData))
(setq EntData (subst (cons 42 (caddr (nth cnt PolyInfoList))) (assoc 42 EntData) EntData))
(setq EntData (subst (cons 40 (cadddr (nth cnt PolyInfoList))) (assoc 40 EntData) EntData))
(setq EntData (subst (cons 41 (last (nth cnt PolyInfoList))) (assoc 41 EntData) EntData))
(entmod EntData)
(setq cnt (1+ cnt))
(if (> cnt (1- (length PolyInfoList)))
(setq cnt 0)
)
)
(if ShouldClose
(progn
(setq EntData (entget Pent))
(entmod (subst '(70 . 1) (assoc 70 EntData) EntData))
)
)
(entupd Pent)
)
;-----------------------------------------------------------
(command "_.undo" "_end")
(command "_.undo" "_group")
(if
(and
(setq Sel (entsel "\n Select polyline: "))
(setq Pt (getpoint "\n Select new starting point: "))
(setq Pobj (vlax-ename->vla-object (car Sel)))
(setq EntData (entget (car Sel)))
(wcmatch (setq Ptype (cdr (assoc 0 EntData))) "*POLYLINE")
)
(if (= Ptype "POLYLINE")
(ChangeOldStyle (car Sel) Pt)
(progn
(setq PtList (vlax-get Pobj 'Coordinates))
(if
(and
(= (vla-get-Closed Pobj) :vlax-false)
(equal (car PtList) (nth (- (length PtList) 2) PtList) 0.0001)
(equal (cadr PtList) (last PtList) 0.0001)
)
(setq ShouldClose T)
)
(setq VertexPt 0)
(setq PtListIndex 0)
(repeat (/ (length PtList) 2)
(vla-GetWidth Pobj VerTexPt 'StWd 'EndWd)
(setq PolyList
(cons
(list
VertexPt
(list
(nth PtListIndex PtList)
(nth (1+ PtListIndex) PtList)
)
(vla-GetBulge Pobj VertexPt)
StWd
EndWd
)
PolyList
)
)
(setq VertexPt (1+ VertexPt))
(setq PtListIndex (+ 2 PtListIndex))
)
(foreach Lst PolyList
(if (equal (list (car Pt) (cadr Pt)) (cadr Lst))
(setq OldIndex (car Lst))
)
)
(setq VertexPt 0)
(setq PtList nil)
(setq PolyList (reverse PolyList))
(setq StPos (vl-position (assoc OldIndex PolyList) PolyList))
(setq cnt StPos)
(repeat (length PolyList)
(setq tmpList (nth cnt PolyList))
(setq PtList (append PtList (cadr tmpList)))
(vla-SetBulge Pobj VertexPt (caddr tmpList))
(vla-SetWidth Pobj VertexPt (cadddr tmpList) (last tmpList))
(setq VertexPt (1+ VertexPt))
(setq cnt (1+ cnt))
(if (> cnt (1- (length PolyList)))
(setq cnt 0)
)
)
(vlax-put Pobj 'Coordinates PtList)
(if ShouldClose
(vla-put-Closed Pobj :vlax-true)
)
)
)
)
(command "_.undo" "_end")
(princ)
)