Nikon Posted 1 hour ago Posted 1 hour ago 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
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.