If what you want is to have whichever end is farther to the left put into a variable called p1, and whichever end is farther to the right put into a variable called p2, no matter which direction the Line was drawn, try this [in simplest terms, minimally tested]:
(defun C:LLtoR ; = Line endpoints ordered from Left to Right
(/ lin endsLtoR)
(setq
lin (car (entsel "\nSelect Line for endpoint ordering: "))
endsLtoR
(vl-sort (list (getpropertyvalue lin "StartPoint") (getpropertyvalue lin "EndPoint"))
'(lambda (a b) (< (car a) (car b)))
); sort
p1 (car endsLtoR)
p2 (cadr endsLtoR)
); setq
(prin1)
)
If a Line is vertical [neither end is to the left or right of the other], its start point will be p1 and its end point will be p2. But it could be made to, for example, put whichever end is lower into p1 and whichever end is higher into p2, or to differentiate by some other standard.
Kent Cooper, AIA