In this section of code
(cond ((vl-consp final)
(drawRect pt1 pt2 ang (* (distance pt1 final) (sin (- (angle pt1 final) ang))))
)
((numberp final)
(drawRect pt1 pt2 ang final)
)
)
You will see if the point (final) can snap to an objects snap points. So you can test it like
(if (osnap final "end")
(setq final (osnap final "end"))
)
This is where Alan's function comes in handy because you can pass the string that is returned to the osnap function.
So I would use it like
(defun get_osmode (/ cur_mode mode$)
(setq mode$ "")
(if (< 0 (setq cur_mode (getvar "osmode")) 16383)
(mapcar
'(lambda (x)
(if (not (zerop (logand cur_mode (car x))))
(setq mode$ (strcat mode$ (cadr x)))
)
)
'(
(0 "_non,")
(1 "_end,")
(2 "_mid,")
(4 "_cen,")
(8 "_nod,")
(16 "_qua,")
(32 "_int,")
(64 "_ins,")
(128 "_per,")
(256 "_tan,")
(512 "_nea,")
(1024 "_qui,")
(2048 "_app,")
(4096 "_ext,")
(8192 "_par")
)
)
)
mode$
)
(setq OsStr (get_osmode))
(if (setq tmpPt (osnap final OsStr))
(setq final tmpPt)
)
Put the above right before this line
(drawRect pt1 pt2 ang (* (distance pt1 final) (sin (- (angle pt1 final) ang))))
Hope that makes sense.