Jump to content

Recommended Posts

Posted

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)

 

Posted

You should post a sample drawing.

Posted (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 by Nikon
Posted (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 by Steven P
  • Thanks 1
Posted

Works in AutoCAD 2026.

 

Try restarting AutoCAD, then a reset to defaults if that doesn't work.

  • Thanks 1
Posted

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.

  • Thanks 1
Posted
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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...