Setting MText Width via LISP

Discussion in 'AutoCAD' started by JRodriguez, Jan 5, 2005.

  1. JRodriguez

    JRodriguez Guest

    Is there a simple routine to change an MTEXT width to 0. For example I have a lot of text strings that their grips run way beyond anything imaginable. What kinda code would I need so that I can run a single command to just select a piece of text and set its width to ZERO (0).

    Any help is greatly appreciated,
    Thanx in advance,
    JRodriguez
     
    JRodriguez, Jan 5, 2005
    #1
  2. JRodriguez

    Doug Broad Guest

    You don't need a program. Just use the properties palette.
    Enter the new width.

    Here is a very crude lisp:
    (defun c:zw ()
    (vlax-put
    (vlax-ename->vla-object
    (car
    (entsel "\nPick Mtext Object: ")))
    'width
    0)
    (princ))
     
    Doug Broad, Jan 5, 2005
    #2
  3. JRodriguez

    JRodriguez Guest

    Sweet. That routine worked. Thanx Doug.

    I was just looking for a quick key cause I find that quicker than using the properties dialog box.

    Thanx again
     
    JRodriguez, Jan 5, 2005
    #3
  4. I'm with Luis in wondering why anyone would want an Mtext's width to be
    zero. Of course it doesn't really mean "zero." It means infinite width, so
    words never wrap. That means if you have enough to require multiple lines
    in the space you have available, you have to use Enters (hard returns,
    carriage returns, whatever). And THAT means that if you ever need to add or
    remove any words to/from the Mtext, you very likely have to go in and
    re-locate the Enters for many or all of the lines, unless you can tolerate
    some real irregularity in line lengths. You have the same problem if the
    paragraph runs too deep for the space available, but you have room to make
    it wider so it can be vertically shorter -- again, you need to go in and
    delete Enters and put them in again in different places. But with Mtext
    with a real width, and no Enters, you just move a grip and everything
    adjusts for you. That's one of the purposes for the existence of Mtext in
    the first place.

    This is the reason I never use the annotation part of Leader, because what
    it gives you is a piece of zero-width Mtext. I'm still steamed at AutoDesk
    over the fact that Help for the Mtext option (Leader command / Annotation /
    Options / Mtext) says:

    "Creates text using the Multiline Text Editor when you specify an insertion
    point and a second point for the text boundary."

    It does not give you any opportunity to specify either point, as far as I
    have been able to determine, and I've really tried to find a way (I'm in
    A2004; maybe it's been "fixed" in 2005). So I write my notes in Mtext
    first, and then I put leaders up to them without using their annotation
    part. It has the disadvantage that if I move the Mtext, the Leader doesn't
    "follow" it, but I find that to be rare, and easier to deal with (e.g.
    moving by way of Stretch and incorporating the end of the Leader) than it is
    to fight with the zero-width annotations.
     
    Kent Cooper, AIA, Jan 6, 2005
    #4
  5. JRodriguez

    OLD-CADaver Guest

    <<I'm with Luis in wondering why anyone would want an Mtext's width to be zero.>>

    Certain types of lists require hard breaks at certain points and disallow wrapping in the middle of an entry. As an example structural steel piperack plans list each member at each elevation in a list where each elevation is a line entity of it's own like:

    W12X40
    W12X40 (-6'-0")
    W12x53 (FPF) (-12'-0")
    W14x60 (FPF) (-18'-0")

    Without hard enters at the end of each line (even with a relatively narrow width) it would look like:

    W12X40 W12X40
    (-6'-0") W12x53
    (FPF) (-12'-0")
    W14x60 (FPF)
    (-18'-0")

    which really doesn't read quite right.

    Now let me jump ahead and answer the next question; "Why not make it wider if you're gonna place hard enters anyway?"

    Well a couple reasons, first inadvertently sliding the grips would force a wordwrap where we don't want one, and primarily, when you move an MTEXT entity with a ) width, you can still see the words, not the bounding box.
     
    OLD-CADaver, Jan 7, 2005
    #5
  6. JRodriguez

    JRodriguez Guest

    WOW you guys had a lot of good questions, answers and concerns. I agree with a bit of all of you guys. I have several conditions like what OLDCADaver was mentioning. Where I just want hard returns. But I also have a lot of random text that I know will never ever need to have a width and will always be single line text. And really this is just something really simple and annoying at the same time. Like the text doesn't matter if it does have grips that are just out in space. But I guess I'd rather just have only one grip (insertion point). And I do agree with the purpose of MTEXT. It was made to have hard returns and to fit text within certain widths. I guess this was just something really finnicky that I wanted to change. My philosophy is that you never ever ever have to settle for default and so I wanted to change it. hehehe

    Well, I hope that I didn't bother, annoy, or confuse anyone by asking about this command. It worked out for what I wanted and I thank you for that Doug. And I also thank the rest of you for speaking your opinions on this situation. I have found myself trying to customize things that pry work out better without being fixed. So its always nice to hear good arguements as to why I would ever think of the madness that I do, hehehe.

    Thanks again to you all!!!
    Jrodriguez
     
    JRodriguez, Jan 7, 2005
    #6
  7. JRodriguez

    OLD-CADaver Guest

    An old one,
    MT0 places zero width Middle Center MTEXT
    410 makes assoc code 41 zreo
    ;;;;;
    (defun c:mt0 ()
    (setvar "cmdecho" 0)
    (setq mtpt (getpoint "\nSelect Text Middle-Center Point: "))
    (setq rtpt (getpoint mtpt "\nSelect Rotation Angle Point: "))
    (command ".mtext" mtpt "r" rtpt "j" "mc" "w" "0")
    )
    ;;;;;;;
    ;;;;;;;
    (defun c:410 ()
    (command ".undo" "BEGIN")
    (setvar "cmdecho" 0)
    (setq
    old (ssget)
    setlgth (sslength old)
    co -1
    t2 "t"
    ht 0
    )
    (while (boundp 't2)
    (progn
    (setq
    co (1+ co)
    temp (entget (ssname old co))
    oldht (assoc 41 temp)
    newht (cons 41 ht)
    newtext (subst newht oldht temp)
    t2 (ssname old (1+ co))
    )
    (entmod newtext)
    )
    )
    (setq co (1+ co))
    (command ".undo" "END")
    (princ)
    )
    ;;;;
     
    OLD-CADaver, Jan 7, 2005
    #7
  8. An alternative but not free... it is the command MTEXTAW, that will reduce the width of mtext to the actual width of the string... from DrawHelp at www.draftteam.com
     
    Luis Esquivel, Jan 7, 2005
    #8
  9. JRodriguez

    doug k Guest

    use quickleader. you can pick mtext width, or not, at your discretion thru
    the settings.
     
    doug k, Jan 7, 2005
    #9
  10. OLD-CADaver's example of a list (like a parts list or bill of materials) is
    a reasonable situation in which zero width could be appropriate, where it's
    not a paragraph-type situation. It gives you a way to make multiple
    "single" (that is, independent) lines of text join together into one entity,
    assuming having them in a fixed relationship to each other is appropriate.

    [One of OLD-CADaver's reasons for zero-width Mtext, namely that you see the
    text content, not just the bounding box, when you drag it, has been overcome
    in 2004. You see the content even with defined-width Mtext.]

    But one of your situations -- "I also have a lot of random text that I know
    will never ever need to have a width and will always be single line text" --
    sounds like a job for plain old Text, rather than Mtext. It has only one
    grip (if it's left-justified), and you see the contents when you move it
    (way back to much earlier versions), and it's easier to edit (you can finish
    with Enter instead of having to pick on the OK button). So unless you want
    to have some words in a text entity be different colors or fonts (which you
    can do with Mtext, but not with Text), I'd suggest that rather than use any
    routine (or the Properties Box) to change Mtext's width to zero, you just
    Explode it instead, and it will become Text.
     
    Kent Cooper, AIA, Jan 7, 2005
    #10
  11. I agree, one line text is so much easier to edit than mtext. Background mask only works with mtext so we are forced to use mtext when we want a background mask. If background mask was smart enough to find the edges of mtext and not the edges of the grips that would be cool!
     
    MarcelGosselin, Jan 7, 2005
    #11
  12. JRodriguez

    OLD-CADaver Guest

    <<has been overcome in 2004. You see the content even with defined-width Mtext>>

    I think I knew that, but we don't upgrade around here in the middle of a project, so half of the production staff (that'd include me) are still on R2002. Thanks for the reminder.


    << plain old Text, rather than Mtext.
    ...
    and it's easier to edit >>

    Not if you use #lisped plus an external editor like wordpad.
     
    OLD-CADaver, Jan 7, 2005
    #12
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.