Reduce Mtext to Actual String Width?

Discussion in 'AutoCAD' started by Simon, Nov 18, 2004.

  1. Simon

    Simon Guest

    Hi all,

    Is there a way to quickly reduce Mtext entities to the actual width of the
    text string? I've got lots of short strings (one word) with big paragraph
    widths, i.e. the grips extend far beyond the actual text. MatchProp is ok,
    but doesn't really reduce widths to the actual string length.

    Simon.
     
    Simon, Nov 18, 2004
    #1
  2. Simon

    Simon Guest

    Thanks, Kate. I have hundreds of these "one liners" at different
    orientations so MatchProp isn't ideal. Is there better method to use?

    Simon.
     
    Simon, Nov 18, 2004
    #2
  3. Simon

    Simon Guest

    Perfect:)

    Thank-you Dean.
     
    Simon, Nov 18, 2004
    #3
  4. Simon

    C Witt Guest

    you could also use this (see attached).. I made it for use with
    multi-line mtext, but it works just as well on single line mtext.
    (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")
    (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)
    )
    (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, Nov 18, 2004
    #4
  5. Simon

    OLD-CADaver Guest

    Lesee'
    Assoc code 41 is the mtext width (distance between grips)
    Assoc code 42 is supposedly the width of the actual words
    So this might work (completely untested):


    (defun c:mtww ()
    (command ".undo" "BEGIN")
    (setvar "cmdecho" 0)
    (setq
    old (ssget)
    setlgth (sslength old)
    co -1
    t2 "t"
    )
    (while (boundp 't2)
    (progn
    (setq
    co (1+ co)
    temp (entget (ssname old co))
    newtext (subst (cons 41 (cdr (assoc 42 temp))) (assoc 41 temp) temp)
    t2 (ssname old (1+ co))
    )
    (entmod newtext)
    )
    )
    (setq co (1+ co))
    (command ".undo" "END")
    (princ)
    )
     
    OLD-CADaver, Nov 18, 2004
    #5
  6. Simon

    Simon Guest

    Both of these work great, and are even quicker than the prop palette.

    Thanks very much, C Witt & OLD-CADaver:)
     
    Simon, Nov 18, 2004
    #6
  7. Simon

    OLD-CADaver Guest

    It worked??? cool. You're welcome.
     
    OLD-CADaver, Nov 18, 2004
    #7
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.