TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dubb 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.
-
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).
-
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!:
-
Works pretty good so far.
-
Excellent :-)
-
How would this work with MLeaders? I have just added the "Multileader" piece. If selects it, but does not unformat it.
(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)
-
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.
-
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:
-
Your width factor looks to be malformed - usually there is a semi-colon following the factor, e.g.:
(1 . "{\\W1.1;MText}")
^---------- Here