Print Page | Close Window

mtext background mask auto-fit

Printed From: CAD Forum
Category: EN
Forum Name: CAD - general
Forum Description: General discussion about CAD, formats, standards, management, licensing, networking, harware, other CAD applications
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=5847
Printed Date: 18.Aug.2026 at 20:49


Topic: mtext background mask auto-fit
Posted By: germanbarry
Subject: mtext background mask auto-fit
Date Posted: 09.May.2011 at 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



Replies:
Posted By: alanjt
Date Posted: 13.May.2011 at 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).

(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)
)



Posted By: alanjt
Date Posted: 13.May.2011 at 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.

; 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)
)




Print Page | Close Window