Okay, like this.
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; draw Mtext
(defun M-Text (pt str ht ang)
(entmakex (list (cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 pt)
(cons 40 ht)
(cons 50 ang)
(cons 1 str)))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; correct - extend if needed
(setq conversionData
'(
("10A" 17.3)
("15A" 21.7)
("20A" 27.2)
("25A" 34)
("32A" 47.7)
("40A" 48.6)
("50A" 60.5)
("65A" 76.3)
("80A" 89.1)
("90A" 101.6)
("100A" 114.3)
("125A" 139.8)
("150A" 165.2)
("175A" 190.7)
("200A" 216.3)
("225A" 241.8)
("250A" 267.4)
("300A" 318.5)
("350A" 355.6)
("400A" 406.4)
)
)
(defun isAppox (s d / tol)
(setq tol 0.2) ;; I'll take a tolerance of 0.2, to be sure
(<
(abs (- s d))
tol
)
)
(defun size2code (s / res)
(setq i 0)
(setq res nil)
(foreach a conversionData
(if (isAppox s (nth 1 a))
(setq res (nth 0 a))
)
)
res
)
(defun c:maa ( / ht ov oh ent nent s code line ip e ang ip2 tmp)
;; settings
(setq ht 75.0) ;; Text height of Mtext
(setq ov 100.0)
(setq oh 24.0)
;; Select DIM, and find code
(setq ent (car (entsel "\nSelect DIM: ")))
;; read text height
(setq ht (vla-get-TextHeight (vlax-ename->vla-object ent)))
(setq ov (/ (* ht 4.0) 3.0))
(setq oh (/ ht 3.0))
(setq s (cdr (assoc 42 (entget ent))))
(setq code (size2code s))
;; Select line
(setq line (car (entsel "\nSelect line: ")))
(setq ip (cdr (assoc 10 (entget line))))
(setq e (cdr (assoc 11 (entget line))))
;; in case start and endpoint are drawn reversed, let's swap them
(if (< (nth 0 e) (nth 0 ip)) (progn
(setq tmp ip)
(setq ip e)
(setq e tmp)
))
(setq ang (angle ip e))
;; Insertpoint of the Mtext. We will put it slightly to the right of the i.P. of the line
(setq ip2 (polar ip (+ ang (/ pi 2)) ov))
(setq ip2 (polar ip2 ang oh))
;; draw Mtext
(M-Text ip2 code ht ang)
(princ)
)