@Anonymous wrote:
Hello, looking for a lisp routine that would change an mtext with 4 lines (1 layer) to 4 separate lines of text (or mtext) and on 4 different layers....
Here's a version that takes a different approach to some operations, and also lets you choose as many Mtext objects as you want all at once. It prevents selection of Mtext on locked Layers.
Since no System Variables are changed that should be assured of being set back, it seems to me the only purpose of an *error* handler is to ensure conclusion of an UNDO begin/end wrapper, so that the whole batch will be undone with one U after running it.
It will work with 4-line Mtexts, but to be more generic, works with those of more [or less] than that. Put more Layer names into the 'laynames' list than the number of lines you expect the Mtext objects to contain, and it will change the Layers of the resulting Text objects as far as they go.
(defun C:MT2L ; = MText {to} Layers
(/ *error* doc laynames ss1 n1 n2 ss2)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(vla-endundomark doc)
(princ)
); defun - *error*
(vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(setq laynames '("1" "2" "3" "4" "5" "6" "7")) ;; <---EDIT
(prompt "\nTo split Mtext object(s) onto different Layers,")
(if (setq ss1 (ssget "_:L" '((0 . "MTEXT"))))
(repeat (setq n1 (sslength ss1)); then
(setq n2 0); set for first, reset for subsequent
(command "_.explode" (ssname ss1 (setq n1 (1- n1))))
(repeat (sslength (setq ss2 (ssget "_P")))
(command "_.chprop" (ssname ss2 n2) "" "_layer" (nth n2 laynames) "")
(setq n2 (1+ n2))
); repeat [Texts]
); repeat [Mtexts]
(prompt "\nNo Mtext(s) on unlocked Layer(s) selected.")
); if
(vla-endundomark doc)
(princ)
); defun
Kent Cooper, AIA