Water Bear,
How about constructing the text before you call the MTEXT command. To determine the size of the text box, you can use TEXTBOX like shown below and try to fit it with some approximate factors. Here I've just used 1.5 times the width and six times the height. You can change it to whatever you think is appropriate but asking the user for anything but the insertion point isn't fair, I think.
(defun elvcalc (/ #bod #cod #conn1 #dep1 #tod #wid1 elvpnt elv_text oldunits txtbox)
(setq oldunits (getvar "lunits"))
(setvar "lunits" 5)
(setq #wid1 (getreal "\nEnter duct WIDTH: ")
#dep1 (getreal "\nEnter duct DEPTH: ")
;;changed this to GETREAL (just for the heck of it)
#bod (getreal "\nEnter BOTTOM elevation: ")
)
;;convert elev from string to REAL calc top & bot elev
;;(setq #bod (distof #bod 4))
;;added some error stuff (just for the heck of it):
(cond
((apply 'and (mapcar 'numberp (list #wid1 #dep1 #bod)))
(setq #conn1 (strcat (rtos #wid1) " X " (rtos #dep1)))
;;calc top & center elev using REALS
(setq #tod (+ #bod #dep1)
#cod (+ #bod (/ #dep1 2))
)
;;convert REALS back to strings, add plus signs(will only be used in tags, not for calc)
(setq #tod (strcat "T+ " (rtos #tod 4 2))
#cod (strcat "C+ " (rtos #cod 4 2))
#bod (strcat "B+ " (rtos #bod 4 2))
)
(setq elv_text (strcat #conn1 "\\P" #tod "\\P" #cod "\\P" #bod))
(setq txtbox (textbox (list (cons 1 elv_text))))
(princ #tod)
(princ #cod)
(princ #bod)
(princ #conn1)
;;added some extra reassuring (just for .. of it)
(cond
((and txtbox (setq elvpnt (getpoint "\nSelect point to insert Elevation text: ")))
(if (null (tblsearch "style" "duc_el"))
(command "style" "duct_el" "romans" "2" "" "20" "" "" "")
)
(command "layer" "m" "SM-Duct Elevations" "c" "4" "" "")
(command "-mtext"
elvpnt
(list (+ (car elvpnt) (* 1.5 (- (caadr txtbox) (caar txtbox))))
(+ (cadr elvpnt) (* 6.0 (- (cadadr txtbox)) (cadar txtbox)))
(caddr elvpnt)
)
elv_text
""
)
)
)
)
)
(setvar "lunits" oldunits)
(princ)
) ;_ end defun