ILoveMadoka Posted 19 hours ago Posted 19 hours ago I found some code by kent1cooper here (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 This works great.... BUT once the width has been changed it no longer works. Is it a simple fix to change the width after it has been changed? Ideally select multiple and not have to pick the dropdown to change. If you have a style that has a defined width, the routine works until you change it to something else. If you run STRIPMTEXT on a string, it resets something so the change text code works again. Quote
Steven P Posted 18 hours ago Posted 18 hours ago (edited) The code is adding a width string to the text. These characters are hidden but will show up if you click on the text and look at it in the properties menu, or via the LISP line: (assoc 1 (entget(car(entsel)))) In the code it adds {\\W'wf'; to the string where wf is the width factor Something like {\\W0.8;Here is a text string} If you run the code again, it will add another width factor to the text string... but won't remove the first, so you get something like this: {\\W0.5;{\\W0.8;Here is a text string}} - noting that the new text width is applied and then the first one is applied.. result is you only see what was applied first. Need to remove this formatting to the text string before applying a new one. You might also have issues if other text formatting is used, such as underlined, italics, bold... For width you might be able to amend Lee Macs Unformat LISP to just unformat the width portion: https://lee-mac.com/unformatstring.html In these text strings replace with just 'W' ACcFfHLlOopQTW and here ACcFfHLlOoPpQSTW change to SW ... and then apply the new width formatting from your LISP .. though CAD is off so not tested - all part of the fun for you! ...if Lee Mac is passing through, feel free to correct me, though many years later I am just about understanding some of your codes. Edited 18 hours ago by Steven P 1 Quote
Lee Mac Posted 14 hours ago Posted 14 hours ago This should achieve the desired result without overriding nested width formatting - (defun c:mtw ( / enx idx sel str wid ) (initget 6) (cond ( (not (setq wid (getreal "\nSpecify new width factor: ")))) ( (setq sel (ssget "_:L" '((0 . "MTEXT")))) (repeat (setq idx (sslength sel)) (setq idx (1- idx) enx (entget (ssname sel idx)) str (assoc 1 enx) ) (entmod (subst (cons 1 (addupdatewidth (cdr str) wid)) str enx)) ) ) ) (princ) ) (defun addupdatewidth ( str wid / ps1 ps2 ps3 ) (cond ( (= "" str) str) ( (and (setq ps1 (vl-string-search "{\\W" str)) (setq ps2 (vl-string-search ";" str ps1)) (setq ps3 (vl-string-search "}" str ps2)) ) (strcat (addupdatewidth (substr str 1 ps1) wid) (substr str (1+ ps1) 3) (rtos wid 2) (substr str (1+ ps2) (- ps3 ps2 -1)) (addupdatewidth (substr str (+ ps3 2)) wid) ) ) ( (strcat "{\\W" (rtos wid 2) ";" str "}")) ) ) (princ) 2 1 Quote
Tsuky Posted 13 hours ago Posted 13 hours ago Your code modified (defun C:MTW ; = MText Width (/ ss wf n mt val_text start end) (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)))) (setq val_text (getpropertyvalue mt "Contents")) (cond ((vl-string-search "{" val_text) (cond ((vl-string-search "\\W" val_text) (setq start (vl-string-search "\\W" val_text) end (vl-string-search ";" val_text 1) ) (repeat (1+ (- end start)) (setq val_text (vl-string-subst "" (chr (vl-string-elt val_text start)) val_text start)) ) (setpropertyvalue mt "Contents" val_text) ) (T (setpropertyvalue mt "Contents" (strcat "{\\W" (rtos wf 2) ";" (vl-string-left-trim "{" val_text) ) ) ) ) ) (T (setpropertyvalue mt "Contents" (strcat "{\\W" (rtos wf 2) ";" (getpropertyvalue mt "Contents") "}") ); setpropertyvalue ) ) ); repeat ); if (princ) ) 1 Quote
ILoveMadoka Posted 1 hour ago Author Posted 1 hour ago (edited) Thank you all for the replies. Lee & Tsuky, Your code works perfectly for me. Steven P, thanks for explaining what was happening under the hood, made perfect sense. As always, I appreciate it greatly!! Edited 1 hour ago by ILoveMadoka 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.