Author Topic: Remove mtext overrides!  (Read 1991 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1082
Remove mtext overrides!
« on: April 10, 2017, 05:28:15 PM »
Is there a native AutoCAD command or work around to remove all mtext property overrides on multiple mtext entities?

https://cadabyss.wordpress.com/ StripMtext v5-0c doesn't work on my 2017 AutoCAD Vanilla

Try StripMtext on the attached file.

Lee Mac

  • Seagull
  • Posts: 12392
  • London, England
Re: Remove mtext overrides!
« Reply #1 on: April 10, 2017, 06:25:45 PM »
Attached is my version of a program to remove all formatting stored in the content of an MText object (note that other formatting options may be stored in other properties associated with the MText object and so this is not as comprehensive as StripMText).

dubb

  • Swamp Rat
  • Posts: 1082
Re: Remove mtext overrides!
« Reply #2 on: April 10, 2017, 06:28:50 PM »
Attached is my version of a program to remove all formatting stored in the content of an MText object (note that other formatting options may be stored in other properties associated with the MText object and so this is not as comprehensive as StripMText).
Sweet! Thanks Lee. :yay!:

dubb

  • Swamp Rat
  • Posts: 1082
Re: Remove mtext overrides!
« Reply #3 on: April 10, 2017, 06:30:45 PM »
Works pretty good so far.

Lee Mac

  • Seagull
  • Posts: 12392
  • London, England
Re: Remove mtext overrides!
« Reply #4 on: April 10, 2017, 06:32:35 PM »
Excellent  :-)

MSTG007

  • Water Moccasin
  • Posts: 2440
  • I can't remeber what I already asked! I need help!
Re: Remove mtext overrides!
« Reply #5 on: April 11, 2017, 07:17:51 AM »
How would this work with MLeaders? I have just added the "Multileader" piece. If selects it, but does not unformat it.

Code: [Select]
(defun c:unformat ( / *error* enx idx rgx sel str )

    (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,MULTILEADER"))))
            (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)
Autodesk Infrastructure Design Suite 2019

Lee Mac

  • Seagull
  • Posts: 12392
  • London, England
Re: Remove mtext overrides!
« Reply #6 on: April 11, 2017, 08:03:41 AM »
I have just added the "Multileader" piece. If selects it, but does not unformat it.

Did you honestly expect it to, after only modifying the selection filter?

You would need to check whether the selected MLeaders have MText content (as opposed to block content or no content), and then unformat and update the value of the first occurrence of DXF group 304, which stores the MText content of an MLeader.

Rittik Das

  • Mosquito
  • Posts: 1
Re: Remove mtext overrides! ERROR
« Reply #7 on: February 13, 2020, 06:01:01 AM »
Hello Lee, I'm a follower of yours and trying to grow my knowledge in automation. I tried you "unformat" lisp, but there is an error showing.
Before using that lisp incidentally added width factor in dxf code, which was equal with the text style width factor. :thinking:

Lee Mac

  • Seagull
  • Posts: 12392
  • London, England
Re: Remove mtext overrides!
« Reply #8 on: February 13, 2020, 12:49:24 PM »
Your width factor looks to be malformed - usually there is a semi-colon following the factor, e.g.:

(1 . "{\\W1.1;MText}")
             ^---------- Here