Your code tells that you use this on horizontal and vertical lines... Is this always the case - I mean if you need to apply it to LWPOLYLINE - it will always be orthogonal? Next thing, you are nil-ing variables before they are declared and not after - is this OK? I'd avoid your way of localization as you may accidentally nil some globals that start with LJ_ and you need them resident for some unknown reason declared if you plan to use them in starting session and you have them set by automatic load procedure when that session starts...
I would suggest you also that you specify gap that'll be used rather then hardcode it in routine as 1.0 - always...
If your LWPOLYLINE is orthogonal you can acquire segment start/end points by using (vlax-curve-getpointatparam) function applied on LW-ename and by providing parameters of beginning segment using (fix (vlax-curve-getpramatpoint lw-ename (vlax-curve-getclosestpointto lw-ename pick-point))) and ending segment parameter (1+ (fix ... =||= ...)). Rest of procedure after getting segment points is the same as with line entity - you just for calculations use instead of start/end points of line, start/end points of LWPOLYLINE segment you picked... And better make sure you use some osnaps for measuring precisely where you want to pick insertion point - (setq pt (getpoint)) function in combination with (nentselp pt) is for me better than (entsel) like in your case...