@BB8x
Give this a try. It's not to cleanup the mess but to do the job right in the first place.
(defun c:foo (/ a n l p s)
;; RJP » 2022-04-28
;; Make Readable - Lee Mac
;; Returns a given angle corrected for text readability
(defun lm:makereadable (a)
((lambda (a)
(if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
(+ a pi)
a
)
)
(rem (+ a pi pi) (+ pi pi))
)
)
(if (setq s (ssget '((0 . "POLYLINE"))))
(foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
(setq n -1)
(setq l (assoc 8 (entget e)))
(repeat (1+ (fix (vlax-curve-getendparam e)))
(setq p (vlax-curve-getpointatparam e (setq n (1+ n))))
(setq a (lm:makereadable (angle '(0 0) (vlax-curve-getfirstderiv e n))))
(entmake (list '(0 . "TEXT")
'(100 . "AcDbEntity")
l
'(100 . "AcDbText")
(cons 10 (polar p (+ a (/ pi 2)) 0.05))
'(40 . 0.18)
(cons 1 (vl-string-subst "," "." (rtos (last p) 2 3)))
(cons 50 a)
'(41 . 1.)
'(51 . 0.)
'(7 . "Standard")
'(71 . 0)
'(72 . 0)
(cons 11 (list 0. 0. (last p)))
'(100 . "AcDbText")
'(73 . 0)
)
)
)
)
)
(princ)
)