@Noor-Cad Give this a try. It will maintain the differing Z vales of your text.
(defun c:foo (/ ln o p pl s txt)
;; RJP » 2024-06-24
(cond ((setq s (ssget ":L" '((0 . "*TEXT,LWPOLYLINE"))))
(foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
(if (= "AcDbPolyline" (vla-get-objectname (setq o (vlax-ename->vla-object e))))
(setq pl o)
(setq txt (cons (list o (vlax-get o 'textalignmentpoint)) txt))
)
)
(if pl
(foreach tx txt
(setq ln (entmakex (list '(0 . "LINE")
(cons 10 (cadr tx))
(cons 11 (mapcar '+ (cadr tx) '(0 1 0)))
'(8 . "TEMPLINE")
)
)
)
(vla-put-elevation pl (last (cadr tx)))
(if (setq p (vlax-invoke (vlax-ename->vla-object ln) 'intersectwith pl 3))
(progn (vlax-put (car tx) 'textalignmentpoint p) (entdel ln))
)
)
)
)
)
(princ)
)