Here is what I use:
(defun tktn_make_scaled_mtext1 (textval textlyr inspt width attach rot / ent)
(entmake
(list
'(0 . "MTEXT")
'(100 . "AcDbEntity")
(cons 8 textlyr)
'(100 . "AcDbMText")
(cons 10 inspt)
(cons 40 (* (tktn_getscl) (getvar "DIMTXT")))
(cons 41 width)
(cons 71 attach)
'(72 . 5)
(cons 1 textval)
(cons 7 (getvar "TEXTSTYLE"))
'(210 0.0 0.0 1.0)
'(11 1.0 0.0 0.0)
(cons 50 rot)
)
)
inspt;return insertion point
);tktn_make_scaled_mtext1
Here is the scaling function:
;;--------------------- tktn_getscl--------------------------------------
;; Purpose: calculate scale factor
;; Uses: nothing
;; Returns: sf
;;-----------------------------------------------------------------
(defun tktn_getscl( )
(cond ((= 1 (getvar "TILEMODE")) (getvar "DIMSCALE"));tiled space
((= 1 (getvar "CVPORT")) 1.0);in paper space
;; in a viewport
(T
(last (trans '(0 0 1.0) 3 2));calc scale factor
)
);cond
);end tktn_getscl
Convert real to MTEXT string:
;;--------------rtomtftin.lsp-----------------------------
;;; Author: Herman Mayfarth
;;; Date: 7 May 2003
;;; Purpose: convert real to MTEXT representation of ft & inches
;;; w/ choice of fraction style
;;; Params: num: real number to convert to MTEXT string
;;; fracht: real specifying the relative ht. of fractions
;;; barsty: string specifying fraction bar style
;;; this must be one of '("/" "^" "#")
;;; Returns: string as above if successful, nil otherwise
;;; Calling function must provide the vertical alignment code
;;;------------------------------------------------------
(defun rtomtftin (num fracht barsty /
add
count
curent
instrg
outstrg
start_format
suffix
)
(setq instrg (rtos num 4 4))
(if (member barsty '("/" "^" "#"));character is allowed
(progn ;call the function
;;three cases exist:
;;Case 1:
;;if we have > 1" and have a fraction, the string will contain a space before
;;the fraction, and we need to substitute the start of the MTEXT format for
;;the space character
;;Case 2:
;;we have >1" but no fraction => no / will be found, and no MTEXT formatting
;;Case 3:
;;we have a fraction <1" => MTEXT formatting prefixes the input string
;setup the format string for the start of the MTEXT fraction
(setq start_format (strcat "{\\H" (rtos fracht 2 2) "x;\\S")
;initialize a counter for the position to test in the input string
count 1
suffix 0
;and bind a null string to a symbol for the output string
outstrg "")
;now walk down the input string one character at a time
(repeat (strlen instrg)
;set a flag to indicate the current character should be kept
(setq add 1
;and get the current character from the input string
curent (substr instrg count 1))
;;first, test for a space character
(cond ((= curent " ");found a space (Case 1),
;; so substitute the fraction format, clear the add flag, and set a flag
;; to let us know we need to close the format at the end
(setq outstrg (strcat outstrg start_format) add nil suffix 1))
;;else test for fraction bar
((= curent "/") ;found a fraction bar
(progn
;;;test for suffix
(if (= suffix 0) (setq suffix 2));need a prefix
;;substitute the value of barsty if necessary, clear the add flag
(if (/= barsty "/");rtos always uses /
(setq outstrg (strcat outstrg barsty) add nil )
)
);progn
);pred
);cond
;if add is bound, there was no substitution, so just add the
;current character to the front of the output string
(if add (setq outstrg (strcat outstrg curent)))
(setq count (1+ count))
);repeat
;;if we found a fraction, we need to close the MTEXT format
(cond ((= suffix 1) (setq outstrg (strcat outstrg ";}")))
((= suffix 2) (setq outstrg (strcat start_format outstrg ";}")))
(T nil);otherwise, do nothing
)
outstrg
);progn
;;do nothing, disallowed separator
);if
);rtomtftin
/code]