Display full version of the post: mtext background mask auto-fit

germanbarry
09.05.2011, 14:16
anyone know of a lisp which lets you select one or many MTEXT entities and have the background mask "hug" the text nice and snugly on say one line of text as default?
 
in an attempt to clarify: you can insert some MTEXT and it might only be 3 letters long but if the mtext box you traced before typing in the text was huge, and the MTEXT has a background mask/BGM, and is also at the front of your draw order, then that text BGM will be acting like a wipeout for the unused portion of its extents.
 
I am hoping to find a lisp which will auto-size the mtext to hug the text nicely (similarly to what microsoft excel does to columns when you double-click on the edge of a column heading/name)
 
obviously this lisp wouldnt apply if you have lots of MTEXTs going over multiple rows/lines within the single MTEXT entity and you want it to stay that way - this lisp would be most ideal for single-line MTEXT scenarios

alanjt
13.05.2011, 04:59

The background mask limits (plus the defined offset) are defined by the width of the MText object. Just set the MText to have a width of zero. Here's a LISP I wrote a while back for doing that very thing. Unless I'm typing notes in paperspace, I create all MText with a zero width (even have a LISP macro to avoid having to specify a zero width each time).[code](defun c:WD (/ ss wd)  ;; Change width of selected MText and MultiLeader objects  ;; Alan J. Thompson, 11.05.09  (vl-load-com)  (if (and (setq ss (ssget "_:L" '((0 . "MTEXT,MULTILEADER"))))           (setq wd (initget 4)                 wd (cond ((getdist "\nWidth <0.0>: "))                          (0.)                    )           )      )    (progn      (vlax-for x (setq ss (vla-get-activeselectionset                             (cond (*AcadDoc*)                                   ((setq *AcadDoc* (vla-get-activedocument                                                      (vlax-get-acad-object)                                                    )                                    )                                   )                             )                           )                  )        (vl-catch-all-apply          (function vlax-put-property)          (list x                (cond ((eq (vla-get-objectname x) "AcDbMText") 'Width)                      ((eq (vla-get-objectname x) "AcDbMLeader") 'TextWidth)                )                wd          )        )      )      (vla-delete ss)    )  )  (princ))[/code]

alanjt2011-05-13 04:59:19

alanjt
13.05.2011, 05:01
Oh yeah, here's the MText LISP macro I use to place MText with a zero width. The really nice thing is, you can right-click/enter at the first getpoint prompt and you'll be able to place MText with a defined width.[code]; mtext with 0 width(defun c:T (/ pt)  (initdia)  (command "_.mtext")  (if (setq pt (getpoint "\nSpecify insertion point <First corner>: "))    (command "_non" pt "_W" 0.)  )  (princ))[/code]