Hi Henrique,
I modified a little the routine.
Now it also includes to modify a TEXT and a single line ATTRIBUTE. The problem is, if I have a block, I need to enter in the BLOCKEDITOR to modify the colors.
My first question is: Is it possible to modify the colors of words contained in MTEXT, TEXT and single line ATTRIBUTE without entering the BLOCKEDITOR?
Just remember: in a MTEXT the change is made to the word/words containing the specified color. In a TEXT and single line ATTRIBUTE, the change is made to the hole TEXT or ATTRIBUTE.
My second question is: would it be possible to include to change the color of the words contained in a multiple lines ATTRIBUTE?
In this case, the change is made in the word/words containing specified color, like in a MTEXT.
Many thanks,
Marcelo
(defun c:ChangeTextColor (/ new obj old ss str)
(if (and (princ "\n Select Text, Mtext or Attribute object to change its color: ")
(setq ss (ssget "_:L" '((0 . "MTEXT,TEXT,ATTDEF"))))
(setq old (getint "\n Enter the old color number:"))
(<= 0 old 256)
(setq new (getint "\n Enter the new color number:"))
(<= 0 new 256)
);and
(progn
(setq ssM (ssget "_P" '((0 . "MTEXT"))))
(command "_.select" ss "")
(setq ssT (ssget "_P" (list (cons 0 "TEXT,ATTDEF")(cons 62 old))))
(if ssM ;MTEXT
(repeat (setq i (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i))))
str (vla-get-textstring obj)
);setq obj
(while (vl-string-search (strcat "\\C" (itoa old) ";") str)
(setq str (vl-string-subst
(strcat "\\C" (itoa new) ";")
(strcat "\\C" (itoa old) ";")
str
);vl
);setq str
);while
(vla-put-textstring obj str)
);repeat
);if ssM ;MTEXT
(if ssT ;TEXT or ATTRIBUTE
(command "_.chprop" ssT "" "c" new "")
);if ssT ;TEXT
);progn
);if and
(princ)
)