It seems closely-enough related that someone looking for the same thing may find this topic. For Mtext that is not already given a width-factor override starting at the beginning of it, this [one way of doing it -- there are others] in simplest terms seems to work:
(defun C:MTW ; = MText Width
(/ ss wf n mt)
(if
(and
(setq ss (ssget "_:L" '((0 . "MTEXT"))))
(setq wf (getreal "\nWidth Factor to apply: "))
); and
(repeat (setq n (sslength ss)); then
(setq mt (ssname ss (setq n (1- n))))
(setpropertyvalue mt "Contents"
(strcat "{\\W" (rtos wf 2) ";" (getpropertyvalue mt "Contents") "}")
); setpropertyvalue
); repeat
); if
(princ)
); defun
I tried it with Mtext that has internal width-factor applied to part of it not at the beginning, and with Mtext that starts out with a color override, and it worked. I haven't tried anything close to all possible combinations of Mtext-editor override possibilities, so there may be cases where it doesn't.
Note that (rtos) will return the width factor as a text string to the number of decimal places in your current Units setting [LUPREC System Variable]. If that might be fewer than your typed entry, it will round it [i.e. if you have LUPREC set to 2 decimal places, and you enter a width factor of 2.125, it will become "2.13"]. If that's a risk you care about, you can add the maximum precision of 8 decimal places in the routine: (rtos wf 2 8) . That will usually put extraneous zeros in the Contents [but they won't affect the outcome], unless you set the DIMZIN System Variable to a value that suppresses trailing zeros [read about it in Help].
Kent Cooper, AIA