Okay so the code I have works if you:
a - Pick the direction going the same as the polyline, no matter the width of any segment
b - pick the direction going the opposite direction of the polyline with a constant width
c - pick the direction going the opposite direction, with the width of the segment pick equal to 0
If the segment is not 0, then it will not update correctly, and I can't seem to find the reason why. Here is the code, and a pic to show what I'm talking about (all polylines go clockwise, drawn with the rectangle command picking upper left to lower right). Guess I should explain that in the pic, the upper right box is the one that is not working. The upper segment should look the same as the one to the left, except the arrow head facing the other direction.
Thanks in advance.
(defun c:Test (/ Sel Pt Obj CoordList cnt ParmPt cnt2 Ang tmpPt1 tmpPt2 Pt2 ArLen ArWidRatio ArAng tmpPt3
OldOs WidFac StWid EndWid ActDoc)
; Add an arrow head in a polyline
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(setq OldOs (getvar 'OsMode))
(if
(and
(setq Sel (entsel "\n Select polyline near where new vertex will be added: "))
(setq Obj (vlax-ename->vla-object (car Sel)))
(= (vla-get-ObjectName Obj) "AcDbPolyline")
(setq Pt (trans (vlax-curve-getClosestPointTo Obj (trans (cadr Sel) 1 0)) 0 (car Sel)))
(setvar 'OsMode 512)
(setq Pt2 (getpoint Pt "\n Direction of arrow and length of arrow: "))
(setq ArLen (distance Pt Pt2))
(setq ArWidRatio (getdist "\n Enter width of polyline to width of arrow ratio: "))
(setq ArAng (angle Pt Pt2))
(setq CoordList (vlax-get Obj 'Coordinates))
)
(progn
(setq cnt 0)
(setq ParmPt 1)
(while (< (1+ cnt) (length CoordList))
(setq cnt2
(if (>= (setq cnt2 (+ 2 cnt)) (length CoordList))
(- cnt2 (length CoordList))
cnt2
)
)
(setq Ang
(angle
(setq tmpPt1
(list
(nth cnt CoordList)
(nth (1+ cnt) CoordList)
)
)
(setq tmpPt2
(list
(nth cnt2 CoordList)
(nth (1+ cnt2) CoordList)
)
)
)
)
(if
(or
(equal (angle Pt tmpPt1) Ang 0.000001)
(equal (angle Pt tmpPt2) Ang 0.000001)
)
(setq cnt (length CoordList))
(progn
(setq ParmPt (1+ ParmPt))
(setq cnt (+ 2 cnt))
)
)
)
(setq tmpPt3 (polar Pt ArAng ArLen))
(if
(vl-catch-all-error-p
(setq StWid (vl-catch-all-apply 'vla-get-ConstantWidth (list Obj)))
)
(vla-GetWidth Obj (1- ParmPt) 'StWid 'EndWid)
(setq EndWid StWid)
)
(setq WidFac
(if (zerop StWid)
1.0
StWid
)
)
(if
(<
(distance tmpPt1 Pt)
(distance tmpPt1 tmpPt3)
)
(progn
(vlax-invoke Obj 'AddVertex ParmPt (list (car Pt) (cadr Pt)))
(vlax-invoke Obj 'AddVertex (1+ ParmPt) (list (car tmpPt3) (cadr tmpPt3)))
(vlax-invoke Obj 'SetWidth ParmPt (+ WidFac (* WidFac ArWidRatio)) 0.0)
)
(progn
(vlax-invoke Obj 'AddVertex ParmPt (list (car tmpPt3) (cadr tmpPt3)))
(vlax-invoke Obj 'AddVertex (1+ ParmPt) (list (car Pt) (cadr Pt)))
(vlax-invoke Obj 'SetWidth ParmPt 0.0 (+ WidFac (* WidFac ArWidRatio)))
)
)
(vlax-invoke Obj 'SetWidth (1- ParmPt) StWid StWid)
(vlax-invoke Obj 'SetWidth (1+ ParmPt) StWid StWid)
)
)
(setvar 'OsMode OldOs)
(vla-EndUndoMark ActDoc)
(princ)
)