Try this, very simple routine.
(defun C:TA
;;; ------- Some Housekeeping ------------------
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq useros (getvar "osmode"))
(setvar "osmode" 1); end point snap
(setq p1 (getpoint "\nSelect first endpoint of line: ")) (setq p2 (getpoint "\nSelect other endpoint of line: ")) (setq d (distance p1 p2)) (setq di (rtos d 2 2)) (setq L_Angle (angle p1 p2)) ; line angle (Setq ang (* L_Angle (/ 180 pi))) (setq ant (angtos ang 4 2)) (setvar "OSMODE" 0) (setq txt (strcat di "'" " " ant)) ; text string
;;; Text offset 4 units distance from line
(If (or (<= L_Angle 1.5708) (> L_Angle 4.71239))
(setq oo 4.0)
(setq oo -4.0)
)
;;; Calculate midpoint of pline
(setq midpt (polar p1 L_Angle (/ d 2.0)))
;;; Calculate text insertion point
(setq txtpt (polar midpt (+ L_Angle (/ pi 2.0))oo )) ;end setq ;;; Convert Text angle from Radians to Degrees (Setq L_Angle (* 180.0 (/ L_Angle pi))) ;;; Adjust angle to keep text upwright (Cond ((and (> L_Angle 90) (<= L_Angle 180)) (setq L_Angle (+ L_Angle 180)) ) ((and (> L_Angle 180) (<= L_Angle 270)) (setq L_Angle (- L_Angle 180)) )
)
;;;Check if the drawing text height is set to 0:
(setq dwg_style (getvar "textstyle"))
(setq styledata (tblsearch "style" dwg_style))
(setq dwg_ht (cdr (assoc 40 styledata)))
;;; If text height is undefined (signified by 0 in the table) (if (= dwg_ht 0) ;;; Draw the text using the current text height (textsize) (command "text" "c" txtpt "" L_Angle txt) ;;; Otherwise use the defined text height (command "text" "c" txtpt L_Angle txt)
) ; endif
;;;========== Exit Sequence ============
(setvar "osmode" useros)
(setvar "CMDECHO" usercmd)
;;; Exit quietly
(princ)
) ; end defun
;;; Notify user program ready to use
(prompt "\nSurvey Labeler Loaded: Type 'TA' to run it.")
(princ)