Here, I've created my version based on Kent's routine - the difference is that you can't miss selection through gaps of not continuous linetypes - it uses temporary creation of helper SPLINE entity, but please read alert message and setup your DWG before processing according to message that pops up...
(defun C:ATapaEnds ( / *error* *adoc* osz cmde ss i spl ent scf bn pt start end dist inspt rotpt )
(vl-load-com)
(defun *error* ( m )
(if osz
(setvar 'osnapz osz)
)
(if cmde
(setvar 'cmdecho cmde)
)
(if (not (vlax-erased-p spl))
(entdel spl)
)
(vla-endundomark *adoc*)
(if m
(prompt m)
)
(princ)
)
(vla-endundomark (setq *adoc* (vla-get-activedocument (vlax-get-acad-object))))
(vla-startundomark *adoc*)
(alert "Check if reference open 2D curves lie in UCS 0.0 elevation... Restart routine when checked...")
(if (setq ss (ssget "_A" '((0 . "*POLYLINE,ELLIPSE,ARC,SPLINE,LINE,HELIX"))))
(progn
(setq osz (getvar 'osnapz))
(setvar 'osnapz 1)
(setq cmde (getvar 'cmdecho))
(setvar 'cmdecho 1)
(prompt "\nCreate temporary helper crossing/fence SPLINE 2D entity that crosses 2D curve entities ONLY ONCE!!!...")
(command "_.spline")
(while (< 0 (getvar 'cmdactive))
(command "\\")
)
(setq spl (entlast))
(setq bn (getstring "\nSpecify block name for insertion process <A-tapa> : "))
(if (= bn "")
(setq bn "A-tapa")
)
(while (not (tblsearch "BLOCK" bn))
(prompt "\nSpecified block name don't exist in DWG database, please specify another name...")
(initget 1)
(setq bn (getstring "\nSpecify block name for insertion process : "))
)
(initget 3)
(setq scf (getreal "\nSpecify scale factor for block insertions : "))
(repeat (setq i (sslength ss))
(setq
ent (ssname ss (setq i (1- i))); the 2D curve from selection set
pt (vlax-invoke (vlax-ename->vla-object spl) 'intersectwith (vlax-ename->vla-object ent) acextendnone)
start (vlax-curve-getStartPoint ent)
end (vlax-curve-getEndPoint ent)
); setq
(if (and pt (setq dist (vlax-curve-getDistAtPoint ent pt)))
(progn
(if (> (- (vlax-curve-getDistAtPoint ent end) dist) dist)
; Fence-crossing point closer to start than end
(setq ; then
inspt (vlax-curve-getStartPoint ent)
rotpt (polar inspt (angle '(0.0 0.0) (vlax-curve-getFirstDeriv ent (vlax-curve-getStartParam ent))) 1.0)
); setq
(setq ; else [closer to end]
inspt (vlax-curve-getEndPoint ent)
rotpt (polar inspt (angle '(0.0 0.0) (vlax-curve-getFirstDeriv ent (vlax-curve-getStartParam ent))) -1.0)
); setq
); if
(command "_.insert" bn "_scale" scf "_none" inspt rotpt)
(command "_.change" (entlast) "" "_p" "_la" (vla-get-layer (vlax-ename->vla-object ent)) "")
); progn
); if
); repeat
); progn
); if
(*error* nil); exit cleanly
); defun
HTH, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)