Author Topic: MTEXT width to match text lenth  (Read 2589 times)

0 Members and 1 Guest are viewing this topic.

notredave

  • Newt
  • Posts: 140
MTEXT width to match text lenth
« on: September 22, 2020, 10:50:06 AM »
Good morning all,

I'm having a time trying to fix mtext through out drawings. I have mtext all over the place that when I double click on it, the bar goes off the screen, length wise. See Example 1 on attach drawing. I would like it to end close to vertical white line at end of text. When I use MTW lisp (attached), mtext width goes to zero but when I drag out the bar, it gives me 1 line per text, see Example 2. What is wrong with this mtext? It's all over my drawings. is there a fix for this? Any help would be greatly appreciated. I've tried stripmtext also to no avail.

Thank you,
David

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: MTEXT width to match text lenth
« Reply #1 on: September 22, 2020, 11:07:28 AM »
Hi,
Replace the subst function with the following:
Code - Auto/Visual Lisp: [Select]
  1. (subst '(41 . 0.0) (assoc 42 e) e)
  2.  

notredave

  • Newt
  • Posts: 140
Re: MTEXT width to match text lenth
« Reply #2 on: September 22, 2020, 11:20:31 AM »
Tharwat,

Thank you for the response. I tried that, it brings ruler to beginning but when I stretch out the ruler to end of longest text, it goes to 1 column, 1 piece of text per line.

Thank you,
David

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: MTEXT width to match text lenth
« Reply #3 on: September 22, 2020, 11:28:52 AM »
Yes correct, and I just gave you the solution to your question to reach the end of that white line.
Try to recreate the Mtext object itself then this should solve the issue though you don't need more codes to do so.

notredave

  • Newt
  • Posts: 140
Re: MTEXT width to match text lenth
« Reply #4 on: September 22, 2020, 11:38:41 AM »
Thank you Tharwat. I appreciate it.

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: MTEXT width to match text lenth
« Reply #5 on: September 22, 2020, 11:44:23 AM »
You're most welcome.

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: MTEXT width to match text lenth
« Reply #6 on: September 22, 2020, 01:39:14 PM »
Hi David,
Please try the following routine to work around the width issue of the Mtext objects and let me know how you get on with it.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:rmt (/ int sel ent)
  2.   ;;    Tharwat - 22.Sep.2020           ;;
  3.   ;; Recreate Mtext objects in order    ;;
  4.   ;; to work around the width.          ;;
  5.   (and (setq int -1
  6.              sel (ssget "_:L" '((0 . "MTEXT")))
  7.        )
  8.        (while (setq int (1+ int)
  9.                     ent (ssname sel int)
  10.               )
  11.          (if (entmake (vl-remove-if-not
  12.                         (function (lambda (u)
  13.                                     (vl-position
  14.                                       (car u)
  15.                                       '(0 100 410 6 8 10 40 62 71 72 1 7
  16.                                         210 50 73)
  17.                                     )
  18.                                   )
  19.                         )
  20.                         (entget ent)
  21.                       )
  22.              )
  23.            (entdel ent)
  24.          )
  25.        )
  26.   )
  27.   (princ)
  28. )
  29.  

notredave

  • Newt
  • Posts: 140
Re: MTEXT width to match text lenth
« Reply #7 on: September 22, 2020, 01:55:21 PM »
Tharwat,

It works great to reverse it. The only problem I see and if you can try it on my example drawing is to run the lisp and after it executes, try and grab the ruler and extend it. It puts it back as one column with one line of text per each line. I'm just going to run it on infinity ruler mtext and be done with it, I'm not going to mess with stretching out ruler. Some idiot must have made mtext with column, that's my guess. Thanks again, I really appreciate it. But both of your routines work!

Thank you,
David

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: MTEXT width to match text lenth
« Reply #8 on: September 22, 2020, 02:04:13 PM »
It works here without going on one line as before now.
Please assure if this is was your goal as shown in the following demo.

notredave

  • Newt
  • Posts: 140
Re: MTEXT width to match text lenth
« Reply #9 on: September 22, 2020, 02:17:16 PM »
Tharwat,

I hope this gif works. This is what I'm talking about after lisp does it thing. I can't stretch ruler back out or else it messes up. I'm just showing you but by no means spend anymore time on this. I will leave it as is. It works great! Thank you very much.

David

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: MTEXT width to match text lenth
« Reply #10 on: September 22, 2020, 03:06:50 PM »
I would not be able to go to sleep tonight if I did not solve the problem.  :laugh:
Please give this a go and be sure you are running this latest routine.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rmt (/ int sel ent get)
  2.   ;;    Tharwat - 22.Sep.2020           ;;
  3.   ;; Recreate Mtext objects in order    ;;
  4.   ;; to work around the width.          ;;
  5.   (and (setq int -1
  6.              sel (ssget "_:L" '((0 . "MTEXT")))
  7.        )
  8.        (while (setq int (1+ int)
  9.                     ent (ssname sel int)
  10.               )
  11.          (and (setq get (entmakex (vl-remove-if-not
  12.                                     (function (lambda (u)
  13.                                                 (vl-position
  14.                                                   (car u)
  15.                                                   '(0   100 410 1   6
  16.                                                     8   10  40  43  44
  17.                                                     62  7   71  72  73
  18.                                                     210 50
  19.                                                    )
  20.                                                 )
  21.                                               )
  22.                                     )
  23.                                     (entget ent)
  24.                                   )
  25.                         )
  26.               )
  27.               (setq
  28.                 get (entmod
  29.                       (subst (cons 1
  30.                                    (Clear_Mtext_String
  31.                                      (cdr (assoc 1 (setq get (entget get))))
  32.                                    )
  33.                              )
  34.                              (assoc 1 get)
  35.                              get
  36.                       )
  37.                     )
  38.               )
  39.               (entmod
  40.                 (subst (cons 41 (cdr (assoc 42 get))) (assoc 41 get) get)
  41.               )
  42.               (entdel ent)
  43.          )
  44.        )
  45.   )
  46.   (princ)
  47. )
  48. (defun Clear_Mtext_String (String / Text Str)
  49.   (setq Text "")
  50.   (while (/= String "")
  51.     (cond ((wcmatch String "\\pxr*;*")
  52.            (setq String (substr String (+ 2 (vl-string-search ";" String))))
  53.           )
  54.           (T
  55.            (setq Text   (strcat Text (substr String 1 1))
  56.                  String (substr String 2)
  57.            )
  58.           )
  59.     )
  60.   )
  61.   Text
  62. )
  63.  
  64.  

notredave

  • Newt
  • Posts: 140
Re: MTEXT width to match text lenth
« Reply #11 on: September 22, 2020, 03:13:45 PM »
WOW!!!

How much do I owe you Tharwat??? Your code is brilliant!! Works like a charm! If you're ever done south in Louisiana, beers are on me.

Thanks again my friend,
David

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: MTEXT width to match text lenth
« Reply #12 on: September 22, 2020, 03:31:12 PM »
Glad to help, and it was full of fun to solve such odd problem.

Thank you for your kind words and for the invitation as well.

notredave

  • Newt
  • Posts: 140
Re: MTEXT width to match text lenth
« Reply #13 on: September 22, 2020, 03:46:29 PM »
It's an open invitation to you Tharwat and my friend ronjonp.

Thanks again for all your help and desire to solve it.

David

ronjonp

  • Needs a day job
  • Posts: 7526
Re: MTEXT width to match text lenth
« Reply #14 on: September 23, 2020, 12:19:20 AM »
It's an open invitation to you Tharwat and my friend ronjonp.

Thanks again for all your help and desire to solve it.

David
Maybe some day we'll have a beer ( or two ).  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

notredave

  • Newt
  • Posts: 140
Re: MTEXT width to match text lenth
« Reply #15 on: September 23, 2020, 07:26:11 AM »
Sounds like a plan ronjonp.