Mtext box resize to largest line routine

Discussion in 'AutoCAD' started by Tom Hanley, Oct 29, 2004.

  1. Tom Hanley

    Tom Hanley Guest

    I'm looking for a routine to resize mtext box to the largest line in the
    mtext box. I understand that if all the text was wordwrapped that would
    happen automatically but we have some text with carriage returns and the
    size of the box can be much larger than the longest line of text. This makes
    the background mask cover more than really needed.
     
    Tom Hanley, Oct 29, 2004
    #1
  2. Tom Hanley

    Tom Smith Guest

    In Properties, change the width to 0.
     
    Tom Smith, Oct 29, 2004
    #2
  3. Tom Hanley

    C Witt Guest

    that won't work if they use a comination of word wrap & "returns"..

    I have attached the lisp that we use for this very reason.. (you may
    want to tweek it a little).

    (defun c:FX (/ sset en el ymt nmt mtwidth mtcont)
    (setq sset (ai_aselect))
    (if (null sset)
    (progn
    (princ "\nNo objects selected.")
    (exit)
    )
    )
    (setq COUNT 0)
    (setq ymt 0)
    (setq nmt 0)
    (if (/= sset nil)(setq EN (ssname sset COUNT))(setq EN nil))
    (WHILE (/= EN nil)
    (setq mtcont nil)
    (setq nel nil)
    (setq EL (entget EN))
    (if (= (cdr (assoc 0 EL)) "MTEXT")
    ;-------------------------------remove extra spaces-----------------------------
    (progn
    (setq mtwidth (* (cdr (assoc 42 el))1.015))
    (setq EL (subst (cons 41 mtwidth) (assoc 41 EL) EL))
    (progn
    (setq nel el)
    (while (/= (assoc 3 nel) nil)
    (setq mtcont
    (if (= mtcont nil)
    (cdr (assoc 3 nel))
    (strcat mtcont (cdr (assoc 3 nel)))
    )
    )
    (setq nel (vl-remove (assoc 3 nel) nel))
    )
    (if (= mtcont nil)
    (setq mtcont (cdr (assoc 1 nel)))
    (setq mtcont (strcat mtcont (cdr (assoc 1 nel))))
    )
    (setq el nel)
    )
    (while (/= (vl-string-search " " mtcont) nil)
    (setq mtcont (vl-string-subst " " " " mtcont))
    )
    (while (/= (vl-string-search " " mtcont) nil)
    (if (= (vl-string-search ". " mtcont) nil)
    (setq mtcont (vl-string-subst " " " " mtcont))
    (setq mtcont (vl-string-subst ".----" ". " mtcont))
    )
    )
    (while (/= (vl-string-search "----" mtcont) nil)
    (setq mtcont (vl-string-subst " " "----" mtcont))
    )
    (setq EL (subst (cons 1 mtcont) (assoc 1 EL) EL))
    (entmod EL)
    ;--------------------------------------------------------------------------------
    (entupd EN)
    (setq COUNT (1+ COUNT))
    (setq EN (SSNAME sset COUNT))
    (setq ymt (1+ ymt))
    )
    (progn
    (setq COUNT (1+ COUNT))
    (setq EN (SSNAME sset COUNT))
    (setq nmt (1+ nmt))
    )
    )
    )
    (prompt (strcat "\n" (itoa ymt) " Mtext object(s) were resized, and " (itoa nmt) " object(s) were not Mtext."))
    (princ)
    )
     
    C Witt, Oct 29, 2004
    #3
  4. Tom Hanley

    C Witt Guest

    this should work for all now.

    (haven't seen his solution yet)

    (defun c:FX (/ sset en el ymt nmt mtwidth mtcont)
    (setq sset (ai_aselect))
    (if (null sset)
    (progn
    (princ "\nNo objects selected.")
    (exit)
    )
    )
    (setq COUNT 0)
    (setq ymt 0)
    (setq nmt 0)
    (if (/= sset nil)(setq EN (ssname sset COUNT))(setq EN nil))
    (WHILE (/= EN nil)
    (setq mtcont nil)
    (setq nel nil)
    (setq EL (entget EN))
    (if (= (cdr (assoc 0 EL)) "MTEXT")
    ;-------------------------------remove extra spaces-----------------------------
    (progn
    (setq mtwidth (* (cdr (assoc 42 el))1.015))
    (setq EL (subst (cons 41 mtwidth) (assoc 41 EL) EL))
    (progn
    (setq nel el)
    (while (/= (assoc 3 nel) nil)
    (setq mtcont
    (if (= mtcont nil)
    (cdr (assoc 3 nel))
    (strcat mtcont (cdr (assoc 3 nel)))
    )
    )
    (setq nel (vl-remove (assoc 3 nel) nel))
    )
    (if (= mtcont nil)
    (setq mtcont (cdr (assoc 1 nel)))
    (setq mtcont (strcat mtcont (cdr (assoc 1 nel))))
    )
    (setq el nel)
    )
    (while (/= (vl-string-search " " mtcont) nil)
    (setq mtcont (vl-string-subst " " " " mtcont))
    )
    (while (/= (vl-string-search " " mtcont) nil)
    (if (= (vl-string-search ". " mtcont) nil)
    (setq mtcont (vl-string-subst " " " " mtcont))
    (setq mtcont (vl-string-subst ".----" ". " mtcont))
    )
    )
    (while (/= (vl-string-search "----" mtcont) nil)
    (setq mtcont (vl-string-subst " " "----" mtcont))
    )
    (setq EL (subst (cons 1 mtcont) (assoc 1 EL) EL))
    (if (= (cdr (assoc 90 EL)) 2)
    (setq el (vl-remove (assoc 90 EL) EL))
    )
    (entmod EL)
    ;--------------------------------------------------------------------------------
    (setq COUNT (1+ COUNT))
    (setq EN (SSNAME sset COUNT))
    (setq ymt (1+ ymt))
    )
    (progn
    (setq COUNT (1+ COUNT))
    (setq EN (SSNAME sset COUNT))
    (setq nmt (1+ nmt))
    )
    )
    )
    (prompt (strcat "\n" (itoa ymt) " Mtext object(s) were resized, and " (itoa nmt) " object(s) were not Mtext."))
    (princ)
    )
     
    C Witt, Oct 29, 2004
    #4
  5. Tom Hanley

    Tom Hanley Guest

    Thanks...Works fine now!

    (itoa nmt) " object(s) were not Mtext."))
     
    Tom Hanley, Oct 29, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.