In this case I am using (ssnamex) to determine which segment of the pline is selected:
((equal etype "LWPOLYLINE")
(progn
(setq vhead (- (length aline) (length (member (assoc 10 aline) aline)))
vpos (nth 2 (car(ssnamex(ssget(cadr alist)))))
p1 (if (assoc 91 aline);later versions have this
(cdr (nth (+ vhead (* 5 (- vpos 1))) aline));quick fix
(cdr (nth (+ vhead (* 4 (- vpos 1))) aline)))
dtype "LWPOLYLINE."
);setq
Complete program is attached, for anyone who wants it.