Having had a proper look, I must say, great code David, I really like your method: clean and intuitive to follow.
I hope you don't mind, I have made some modifications to condense the code and perhaps improve performance:
(defun c:Slice3DPoly ( / _FindZOnLine ed en i p1 p2 pl sl ss tp vd vl )
;; A modification by Lee Mac of the code by David Bethel found here:
;; http://www.cadtutor.net/forum/showthread.php?62556-3D-polyline-Intersection&p=426585&viewfull=1#post426585
(defun _FindZOnLine ( fp p1 p2 )
(cond
( (or (equal p1 p2 1e-11)
(equal (caddr p1) (caddr p2) 1e-11)
(equal (list (car p1) (cadr p1)) (list (car p2) (cadr p2)) 1e-11)
)
(caddr p1)
)
( (+ (caddr p1)
(* (- (caddr p2) (caddr p1))
(/ (distance (list (car p1) (cadr p1)) (list (car fp) (cadr fp)))
(distance (list (car p1) (cadr p1)) (list (car p2) (cadr p2)))
)
)
)
)
)
)
(if
(and
(setq p1 (getpoint "\nSpecify First Point: "))
(setq p2 (getpoint "\nSpecify Second Point: " p1))
(setq ss (ssget "_F" (list p1 p2) '((0 . "POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 118) (-4 . "NOT>"))))
)
(progn
(repeat (setq i (sslength ss))
(setq en (ssname ss (setq i (1- i)))
ed (entget en)
en (entnext en)
vd (entget en)
vl nil
)
(while (eq "VERTEX" (cdr (assoc 0 vd)))
(setq vl (cons (cdr (assoc 10 vd)) vl)
en (entnext en)
vd (entget en)
)
)
(if (= 1 (logand 1 (cdr (assoc 70 ed))))
(setq sl (cons (mapcar 'list vl (append (cdr vl) (list (car vl)))) sl))
(setq sl (cons (mapcar 'list vl (cdr vl)) sl))
)
)
(foreach s (apply 'append sl)
(if
(setq tp
(inters p1 p2
(list (caar s) (cadar s))
(list (caadr s) (cadadr s))
)
)
(setq pl (cons (list (car tp) (cadr tp) (_FindZOnLine tp (car s) (cadr s))) pl))
)
)
(entmakex '((0 . "POLYLINE") (10 0.0 0.0 0.0) (70 . 8)))
(foreach x
(vl-sort pl
(function
(lambda ( a b )
(< (distance p1 (list (car a) (cadr a)))
(distance p1 (list (car b) (cadr b)))
)
)
)
)
(entmakex (list '(0 . "VERTEX") (cons 10 x) '(70 . 32)))
)
(entmakex '((0 . "SEQEND")))
)
)
(princ)
)
(vl-load-com) (princ)