change text color

change text color

diegolopezsilanes
Advocate Advocate
2,089 Views
3 Replies
Message 1 of 4

change text color

diegolopezsilanes
Advocate
Advocate

Hi, i have a program that copies the value from a text to another and i'd like the modified text to change color to red

(defun c:cpytxtval (/ oldcmd ss0 ss1 i ent0 ent1 elist1 sorText) ;; copy text value
 (setvar "cmdecho" 0)

 (command "._undo" "_begin")
(setq oldcmd (getvar "PICKBOX"))
(SETVAR "PICKBOX" 15)


 (princ "\nSelect source text.")
 (if (setq ss0 (ssget  '((0 . "text,mtext")))) ; select single text entity

;(ssget ":S" '((0 . "text,mtext")))) ; select single text entity
;MODIFICADO 15 octubre 2018 

  (progn
   (redraw (setq ent0 (ssname ss0 0)) 3) ; highlight source text
   (setq sorText (cdr (assoc 1 (entget ent0))))

   (princ "\nSelect target text(s)")
   (if (setq ss1 (ssget '((0 . "text,mtext")))) ; let user select only text entities
    (progn
     (setq i -1)
     (while (setq ent1 (ssname ss1 (setq i (1+ i))))
      (setq elist1 (entget ent1))
      (setq elist1 (subst (cons '1 (strcase sorText)) (assoc '1 elist1) elist1))
(setq COL 71)
(setq elist1(subst (cons 1 COL)(assoc 62 elist1) elist1))
      (entmod elist1)
     ); while
    ); progn
   ); if
  ); progn
 ); if

 (redraw ent0 4); de highlight source text

(SETVAR "PICKBOX" oldcmd )

 (command "._undo" "_end")
;(command "CAMBPROP" SS1 "" "CO" "71" "")
 (setvar "cmdecho" 1)
); c:cpytxtval
0 Likes
Accepted solutions (2)
2,090 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

>>> (setq elist1(subst (cons 1 COL)(assoc 62 elist1) elist1))
Not 1:
(setq elist1 (subst (cons 62 COL) (assoc 62 elist1) elist1))
 
But [I don't have AutoCAD open to confirm] I think that may not work if the target text's color is ByLayer, because there will not be an (assoc 62) entry to substitute.  If that's true, try this:

(setq elist1

   (if (assoc 62 elist1); does it have a color entry?

     (subst (cons 62 COL) (assoc 62 elist1) elist1); then [replace it]

     (append elist1 (list (cons 62 COL))); else [add it]

  ); if

); setq

Kent Cooper, AIA
0 Likes
Message 3 of 4

dbhunia
Advisor
Advisor
Accepted solution

@diegolopezsilanes wrote:

Hi, i have a program that copies the value from a text to another and i'd like the modified text to change color to red

(defun c:cpytxtval (/ oldcmd ss0 ss1 i ent0 ent1 elist1 sorText) ;; copy text value
 (setvar "cmdecho" 0)

 (command "._undo" "_begin")
(setq oldcmd (getvar "PICKBOX"))
(SETVAR "PICKBOX" 15)


 (princ "\nSelect source text.")
 (if (setq ss0 (ssget  '((0 . "text,mtext")))) ; select single text entity

;(ssget ":S" '((0 . "text,mtext")))) ; select single text entity
;MODIFICADO 15 octubre 2018 

  (progn
   (redraw (setq ent0 (ssname ss0 0)) 3) ; highlight source text
   (setq sorText (cdr (assoc 1 (entget ent0))))

   (princ "\nSelect target text(s)")
   (if (setq ss1 (ssget '((0 . "text,mtext")))) ; let user select only text entities
    (progn
     (setq i -1)
     (while (setq ent1 (ssname ss1 (setq i (1+ i))))
      (setq elist1 (entget ent1))
      (setq elist1 (subst (cons '1 (strcase sorText)) (assoc '1 elist1) elist1))
;(setq COL 71)
;(setq elist1(subst (cons 1 COL)(assoc 62 elist1) elist1))
      (entmod elist1)
(command "_CHPROP" ent1 "" "CO" "1" "") ); while ); progn ); if ); progn ); if (redraw ent0 4); de highlight source text (SETVAR "PICKBOX" oldcmd ) (command "._undo" "_end") ;(command "CAMBPROP" SS1 "" "CO" "71" "") (setvar "cmdecho" 1) ); c:cpytxtval

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 4 of 4

dlanorh
Advisor
Advisor
(defun c:cpytxtval (/ sv_vals sv_lst s_ent s_txt ss cnt e_lst t_ent) ;; copy text value

  (setq sv_vals (mapcar 'getvar (setq sv_lst (list 'cmdecho 'pickbox))))
  (mapcar 'setvar sv_lst '(0 15))
  
  (command "._undo" "_begin")
  (prompt "Select Source Text : ")
  (cond ( (setq s_ent (ssname (ssget "_+.:E:S:L" '((0 . "*TEXT"))) 0))
          (redraw s_ent 3)
          (setq s_txt (cdr (assoc 1 (entget s_ent))))
          (prompt "Select Target for Text : ")
          (setq ss (ssget ":L" '((0 . "*TEXT"))))
          (redraw s_ent 4)
          (if ss 
            (repeat (setq cnt (sslength ss))
              (setq e_lst (entget (setq t_ent (ssname ss (setq cnt (1- cnt)))))
                    e_lst (subst (cons 1 (strcase s_txt)) (assoc 1 e_lst) e_lst)
              );end_setq
              (if (setq col (cdr (assoc 62 e_lst)))
                (setq e_lst (subst (cons 62 1) (assoc 62 e_lst) e_lst))
                (setq e_lst (append '((62 . 1)) e_lst))
              );end_if
              (entmod e_lst)
              (entupd t_ent)
            );end_repeat
          );end_if  
        )
  );end_cond
  (command "._undo" "_end")
  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_c:cpytxtval

I am not one of the robots you're looking for

0 Likes