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

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 945
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: 11799
  • AutoCAD 2015 Windows 7 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: 945
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: 945
Re: Remove mtext overrides!
« Reply #3 on: April 10, 2017, 06:30:45 pm »
Works pretty good so far.

Lee Mac

  • Seagull
  • Posts: 11799
  • AutoCAD 2015 Windows 7 London, England
Re: Remove mtext overrides!
« Reply #4 on: April 10, 2017, 06:32:35 pm »
Excellent  :-)

MSTG007

  • Water Moccasin
  • Posts: 2027
  • 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 2017

Lee Mac

  • Seagull
  • Posts: 11799
  • AutoCAD 2015 Windows 7 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.