Nikon Posted Wednesday at 05:41 PM Posted Wednesday at 05:41 PM This code does not work in Autocad 2021 (localized version), the selected MText is being deleted. How can this be fixed? ; UnFormat MText, MLeader, Table - strip formatting contol codes from texts ; ; based on Lee Mac's UnFormat string - www.lee-mac.com/unformatstring.html ; CAD Studio, 2018, www.cadstudio.cz www.cadforum.cz ; ; (vl-load-com) ;;-------------------=={ 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 ) ) ) ) ;----------------- (defun doUnformatTable (table / rowCounter colCounter) (setq rowCounter (vla-Get-Rows table)) (repeat rowCounter (setq rowCounter (1- rowCounter)) (setq colCounter (vla-Get-Columns table)) (repeat colCounter (setq colCounter (1- colCounter)) (setq cellType (vla-GetCellType table rowCounter colCounter)) (if (= cellType acTextCell)(progn (setq cellText (vla-GetText table rowCounter colCounter)) (if (/= cellText "") (vla-SetText table rowCounter colCounter (LM:UnFormat cellText T))) )) ) ; rep ) ; rep ) (defun c:UNFORMAT (/ ss ssl cnt en xxobj otyp txr ntx) (princ "\nSelect MTEXTs/DIMENSIONs/MLEADERs/TABLEs: ") (setq ss (ssget '((0 . "MTEXT,DIMENSION,MULTILEADER,ACAD_TABLE")))) (if (and ss (> (setq ssl (sslength ss)) 0))(progn (setq cnt 0) (repeat ssl (setq en (ssname ss cnt)) (setq obj (vlax-ename->vla-object en)) (setq otyp (cdr (assoc 0 (entget en)))) ; (vla-get-objectname obj)) (cond ((= otyp "MTEXT")(vla-put-TextString obj (LM:UnFormat (vla-get-TextString obj) T))) ; AcDbMText ((= otyp "DIMENSION")(vla-put-TextOverride obj (LM:UnFormat (vla-get-TextOverride obj) T))) ; AcDbRotatedDimension, AcDbAlignedDimension ((= otyp "MULTILEADER")(vla-put-TextString obj(LM:UnFormat (vla-get-TextString obj) T))) ; AcDbMLeader ((= otyp "ACAD_TABLE")(doUnformatTable obj)) ; AcDbTable ) (setq cnt (1+ cnt)) ) ;rep ) (princ "\nNothing selected!") ) ;if (princ) ) (princ "\nUNFORMAT loaded.") (princ) Quote
ronjonp Posted Wednesday at 08:12 PM Posted Wednesday at 08:12 PM You should post a sample drawing. Quote
Nikon Posted Thursday at 05:39 AM Author Posted Thursday at 05:39 AM (edited) 9 hours ago, ronjonp said: You should post a sample drawing. In Autocad 2015, the code worked correctly, in Autocad 2021, texts containing control codes are deleted after selection... Unformat not work in Autocad 2021.dwg Edited Thursday at 05:41 AM by Nikon Quote
Steven P Posted Thursday at 08:22 AM Posted Thursday at 08:22 AM (edited) It was working OK for me in your sample drawing - I am using 2022 though but would expect any changes in 2021 to be carried through to that. Looking at the LISP, there is nothing in there to delete any texts, try loading it last in case there is another LISP loaded with the same name as some of the sub routines and try again maybe Edited Thursday at 08:24 AM by Steven P 1 Quote
SLW210 Posted Thursday at 10:27 AM Posted Thursday at 10:27 AM Works in AutoCAD 2026. Try restarting AutoCAD, then a reset to defaults if that doesn't work. 1 Quote
GLAVCVS Posted Thursday at 12:23 PM Posted Thursday at 12:23 PM If you haven't solved it yet, there's another possibility: Replace '(setq en (ssname ss cnt))' with '(setq en (ssname ss cnt)) ex en)' Load the code and run it again. Then, type '(entget ex)' on the command line. If it returns the entity list, see if '(60 . 1)' appears anywhere. 1 Quote
Nikon Posted Thursday at 02:43 PM Author Posted Thursday at 02:43 PM 2 hours ago, GLAVCVS said: If you haven't solved it yet, there's another possibility: Replace '(setq en (ssname ss cnt))' with '(setq en (ssname ss cnt)) ex en)' Load the code and run it again. Then, type '(entget ex)' on the command line. If it returns the entity list, see if '(60 . 1)'. texts containing control codes are deleted after selection... Reaction to the Command: (entget ex) ; error: invalid argument type: lentityp nil Quote
GLAVCVS Posted 3 hours ago Posted 3 hours ago I agree with StevenP. I've tested Lee Mac's code in the 2021 version, and it works fine in your drawing. It's probably some interference between your loaded Lisp code. 1 Quote
Nikon Posted 3 hours ago Author Posted 3 hours ago (edited) 55 minutes ago, GLAVCVS said: I agree with StevenP. I've tested Lee Mac's code in the 2021 version, and it works fine in your drawing. It's probably some interference between your loaded Lisp code. Is there a way to find this intervention? I have two more codes with this function that don't work... Edited 3 hours ago by Nikon Quote
Steven P Posted 2 hours ago Posted 2 hours ago (edited) Try this as an experiment: (Defun C:LMUnF ( / ) (Load " -NIKON LISP FILEPATH- \\LM-Unformat.lsp") (c:UNFORMAT)(princ) ) Where -Nikon Lisp Filepath is where the file is saved, LM-Unformat.lsp is the file name. It should load this file when you run 'LMUnf' - and since it is the latest loaded will take precedence over anything loaded previously, Second option is to modify the text using entmod perhaps Edited 1 hour ago by Steven P 1 Quote
Nikon Posted 11 minutes ago Author Posted 11 minutes ago (edited) 1 hour ago, Steven P said: It should load this file when you run 'LMUnf' - and since it is the latest loaded will take precedence over anything loaded previously, Thank you all for your advice. I've tried all the options. It doesn't work… There is no file UNFORMAT in the startup, I open a new file, download lisp UNFORMAT and nothing changes... Mysticism?!? Edited 10 minutes ago by Nikon 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.