ILoveMadoka Posted October 28, 2021 Posted October 28, 2021 (edited) <Update:> The issue I encountered was a drawing converted from VISIO to Autocad. If I convert the fonts to ARIAL beforehand, I can use STRIPMTEXT if not I have to use one of the methods below. I have several drawings filled with MText objects. If I select them all and attempt to change via the Properties dialog a new height is then displayed but the text height does not change. If I double click on one of the objects the Text Formatting bar appears and a different text height is shown there. I thought that Lee's STRIPMTEXT would resolve this but running it leaves me with the same issue afterwards. This may be the wrong forum but if anyone knows of a routing to resolve this I would appreciate being pointed to it please.. I have hundreds of text objects to change. Please advise. (feel free to move this thread if it shouldn't be here) Edited November 30, 2021 by ILoveMadoka Quote
ILoveMadoka Posted October 28, 2021 Author Posted October 28, 2021 (edited) Just to show that I am using Stripmtext After I ran that routine, I tried changing the objects to a different style then changing them back but I still have the discrepancy between the Properties Dialog and the Text Formatting bar. Edited October 28, 2021 by ILoveMadoka Quote
mhupp Posted October 28, 2021 Posted October 28, 2021 (edited) From what i remember about AutoCAD your standard style text height is set to 0.0938 and is overwriting anything you change it to. if you change that value to 0 it defualts to user defined heights. this is why it works when you change it to another style it has a value of 0 probably. BriscsCAD it will default to the style text height when creating any text but allows you to change it to what ever you want. --Edit-- same applys to dimsyle Edited October 28, 2021 by mhupp 1 Quote
Steven P Posted October 28, 2021 Posted October 28, 2021 I forget how to make it do this, but strip Mtext usually works, I don' think SMT is one of Lees, happy to be corrected if I am wrong, but he does have this: http://lee-mac.com/unformatstring.html which removes mtext formatting - can't say I have ever used it for this though, but it could be something to try Quote
BIGAL Posted October 28, 2021 Posted October 28, 2021 If all the mtext has a default height then using Vla-put-height will work or entmod code 40 which is height. aaa nnn ccc If the text has a height over ride it will have something like this ; TextString = "aaa {\\H2x;nnn} ccc", Height by 2, so removing the formatting should fix then change height. Quote
ILoveMadoka Posted October 29, 2021 Author Posted October 29, 2021 It was really strange, if I ran the stripmtext on a single string it worked if I tried larger selections sets it did not. I saw the formatting for the height was there but didn't know how to remove it for all the text that I had to change. I wish I had seen Lee's Unformat String. I ended up having to destroy the drawing then rebuild it from scratch for the most part. It's taken me 2 days to get it "correct" sigh.. appreciate all the feedback.. I'll know next time. 1 Quote
Steven P Posted October 29, 2021 Posted October 29, 2021 For another time, instead of rebuilding the drawing if it all fails, you could explode the mtext to basic text and then txt2mtxt to recombine it, might be quicker and should also remove all the mtext formatting.. but will still take time Quote
ILoveMadoka Posted November 1, 2021 Author Posted November 1, 2021 Has anyone created a routine using Lee's Unformat so that I could select and process all mtext? I do not understand that code enough to know how to use it. Seems straightforward but it's out of my league.. Quote
ILoveMadoka Posted November 1, 2021 Author Posted November 1, 2021 On 10/29/2021 at 12:28 PM, Steven P said: For another time, instead of rebuilding the drawing if it all fails, you could explode the mtext to basic text and then txt2mtxt to recombine it, might be quicker and should also remove all the mtext formatting.. but will still take time that is what I ended up doing. It was several drawings full of text so it was two days of fun... Quote
ILoveMadoka Posted November 1, 2021 Author Posted November 1, 2021 On 10/28/2021 at 1:03 PM, Steven P said: I forget how to make it do this, but strip Mtext usually works, I don' think SMT is one of Lees, happy to be corrected if I am wrong, but he does have this: http://lee-mac.com/unformatstring.html which removes mtext formatting - can't say I have ever used it for this though, but it could be something to try correct. It's here (STRIPMTEXT) Quote
tombu Posted November 2, 2021 Posted November 2, 2021 On 11/1/2021 at 6:24 AM, ILoveMadoka said: correct. It's here (STRIPMTEXT) History and a few fixes for specific issues may be found https://www.theswamp.org/index.php?topic=31584.0 few from other authors https://www.theswamp.org/index.php?topic=14764.msg178357#msg178357 Quote
ILoveMadoka Posted November 9, 2021 Author Posted November 9, 2021 Can Lee's UNFORMATSTRING be incorporated into a routine with a selection set? I don't understand what it does to even attempt something. This is the code from Lee's site ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; (defun LM:UnFormat ( str mtx / _replace rx ) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) (vl-load-com) Quote
mhupp Posted November 9, 2021 Posted November 9, 2021 (edited) Have to feed it a string. then the mtx is if its just oputs txt or input back into mtext. str - String to Process mtx - MText Flag (T if string is for use in MText) This should strip all mtext of their formatting. (defun C:UnFormat-MTEXT (/ ss txt a ent entity) (setq SS (ssget "_X" '((0 . "MTEXT")))) (foreach ent (mapcar 'cadr (ssnamex SS)) (setq txt (LM:gettextstring ent)) (setq txt (LM:UnFormat txt t)) (setq entity (entget ent)) (entmod (subst (cons 1 txt) (assoc 1 entity) entity)) ) (princ) ) (defun LM:gettextstring (ent / enx itm str typ) (setq enx (entget ent) typ (cdr (assoc 0 enx)) ) (cond ((wcmatch typ "TEXT,*DIMENSION") (cdr (assoc 1 (reverse enx))) ) ((and (= "MULTILEADER" typ) (= 5 (cdr (assoc 172 enx))) ) (cdr (assoc 304 enx)) ) ((wcmatch typ "ATTRIB,MTEXT") (setq str (cdr (assoc 1 (reverse enx)))) (while (setq itm (assoc 3 enx)) (setq str (strcat (cdr itm) str) enx (cdr (member itm enx)) ) ) str ) ) ) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; (defun LM:UnFormat (str mtx / _replace rx) (vl-load-com) (defun _replace (new old str) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda () (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ( "\032" . "\\\\\\\\") ( " " . "\\\\P|\\n|\\t") ( "$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ( "$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ( "$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ( "$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) Edited November 9, 2021 by mhupp Quote
ILoveMadoka Posted November 9, 2021 Author Posted November 9, 2021 That works PERFECTLY!! <Awesome! THANK YOU!!> I wanted to make one change but I cannot incorporate it correctly.. I want the option to run the routine on ALL or on a Selection Set. How do I add/incorporate this? (initget "All Select") (setq select (getkword "\nSelect text to change: <A>ll or <S>elect? ")) (if select (cond ((= select "All")(setq SS (ssget "_X" '((0 . "MTEXT"))))) ((= select "Select")(setq SS (ssget))) )) The following DOES NOT WORK for me. I get Invalid Option Keyword. I'd like to know what I did wrong or was missing since I'm trying to learn.. (defun C:UnFormat-MTEXT (/ ss txt a ent entity) (initget "All Select") (setq select (getkword "\nSelect text to change: <A>ll or <S>elect? ")) (if select (cond ((= select "All")(setq SS (ssget "_X" '((0 . "MTEXT"))))) ((= select "Select")(setq SS (ssget))) )) (foreach ent (mapcar 'cadr (ssnamex SS)) (setq txt (LM:gettextstring ent)) (setq txt (LM:UnFormat txt t)) (setq entity (entget ent)) (entmod (subst (cons 1 txt) (assoc 1 entity) entity)) ) (princ) ) (defun LM:gettextstring (ent / enx itm str typ) (setq enx (entget ent) typ (cdr (assoc 0 enx)) ) (cond ((wcmatch typ "TEXT,*DIMENSION") (cdr (assoc 1 (reverse enx))) ) ((and (= "MULTILEADER" typ) (= 5 (cdr (assoc 172 enx))) ) (cdr (assoc 304 enx)) ) ((wcmatch typ "ATTRIB,MTEXT") (setq str (cdr (assoc 1 (reverse enx)))) (while (setq itm (assoc 3 enx)) (setq str (strcat (cdr itm) str) enx (cdr (member itm enx)) ) ) str ) ) ) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; (defun LM:UnFormat (str mtx / _replace rx) (vl-load-com) (defun _replace (new old str) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda () (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ( "\032" . "\\\\\\\\") ( " " . "\\\\P|\\n|\\t") ( "$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ( "$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ( "$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ( "$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) Quote
tombu Posted November 9, 2021 Posted November 9, 2021 Getkwords must match initget try: (getkword "\nSelect text to change: All or Select? ") A, S, All, Select, all & select would all be valid responses as well as picking with the mouse. 1 Quote
marko_ribar Posted November 9, 2021 Posted November 9, 2021 (edited) Try this mod... (defun C:UnFormat-MTEXT ( / select ss txt entity ) (initget "All Select") (setq select (getkword "\nSelect text to change [All/Select] <Select> : ")) (if select (cond ( (= select "All") (setq SS (ssget "_X" '((0 . "MTEXT")))) ) ( (= select "Select") (setq SS (ssget "_:L")) ) ) (setq SS (ssget "_:L")) ) (foreach ent (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex SS))) (setq txt (LM:gettextstring ent)) (setq txt (LM:UnFormat txt t)) (setq entity (entget ent)) (entupd (cdr (assoc -1 (entmod (subst (cons 1 txt) (assoc 1 entity) entity))))) ;;; I am not sure about DXF 1 Group Code for MTEXT... ) (princ) ) Edited November 9, 2021 by marko_ribar 2 Quote
ILoveMadoka Posted November 9, 2021 Author Posted November 9, 2021 Both of those worked perfectly.. Thank you. Quote
mhupp Posted November 9, 2021 Posted November 9, 2021 (edited) This sets the default option. (initget "All Select") (setq select (cond ((getkword "\nSelect text to change [All/Select] <Select> : ")) ("Select") ) ) (cond ((= select "Select") (setq SS (ssget "_:L" '((0 . "MTEXT"))))) ; Prob should limit the selection to mtext. don't know if the entmod would error if other things where picked. ((= select "All") (setq SS (ssget "_X" '((0 . "MTEXT"))))) ) Edited November 9, 2021 by mhupp 1 Quote
ILoveMadoka Posted November 9, 2021 Author Posted November 9, 2021 Thank you. Thanks to everyone! This is a tremendous help! 1 Quote
ILoveMadoka Posted November 30, 2021 Author Posted November 30, 2021 Again, thank you everyone. I ran across this after the fact and I love it... (Thanks once more to LeeMac!!) I wanted to post this for anyone who may need it in the future. (defun c:unformat ( / *error* enx idx rgx sel str ) ;;;https://www.theswamp.org/index.php?topic=52929.msg577561 ;;;LeeMac (defun *error* ( msg ) (if (and (= 'vla-object (type rgx)) (not (vlax-object-released-p rgx))) (vlax-release-object rgx) ) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (cond ( (or (vl-catch-all-error-p (setq rgx (vl-catch-all-apply 'vlax-get-or-create-object '("vbscript.regexp")))) (null rgx) ) (princ "\nUnable to interface with RegExp object.") ) ( (setq sel (ssget "_:L" '((0 . "MTEXT")))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) str (assoc 1 enx) ) (entmod (subst (cons 1 (LM:quickunformat rgx (cdr str))) str enx)) ) ) ) (*error* nil) (princ) ) ;; Quick Unformat - Lee Mac ;; Returns a string with all MText formatting codes removed. ;; rgx - [vla] Regular Expressions (RegExp) Object ;; str - [str] String to process (defun LM:quickunformat ( rgx str ) (if (null (vl-catch-all-error-p (setq str (vl-catch-all-apply '(lambda nil (vlax-put-property rgx 'global actrue) (vlax-put-property rgx 'multiline actrue) (vlax-put-property rgx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHKkLlOopQTW])|\\\\[ACcFfHKkLlOopQTW][^\\\\;]*;|\\\\[ACcFfKkHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ("\\$1$2$3" . "(\\\\[ACcFfHKkLlOoPpQSTW])|({)|(})") ("\\\\" . "\032") ) (vlax-put-property rgx 'pattern (cdr pair)) (setq str (vlax-invoke rgx 'replace str (car pair))) ) ) ) ) ) ) str ) ) (vl-load-com) (princ) 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.