Jump to content

Change Text Color


ScoRm

Recommended Posts

I have this Copy paste autolisp that i stitched up from various people(because IDK how to code)

but i am stuck.. what i want to do is select all text and change them all

my copy pasted code is for single text...

(defun c:TcolAu (/ hcol clr pt1 ss)
(While T
(setq ss (ssget "_:S" '((0 . ",TEXT"))))
(setq hcol (atof(cdr (assoc 1 (entget (ssname ss 0))))))
(cond
 ((<= hcol 0.09)(setq clr 252))
 ((<= hcol 0.49)(setq clr 5))
 ((<= hcol 0.99)(setq clr 3))
 ((<= hcol 1.99)(setq clr 2))
 ((<= hcol 2.99)(setq clr 30))
 ((>= hcol 3)(setq clr 6))
)
(command "change" ss "" "_p" "Color" clr "")
(princ)))

Link to comment
Share on other sites

quick google :

 

 

; [url]https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-text-and-change-color/td-p/1974137[/url]
(defun c:cc  (/ string color texts) ;Change Color
 (setq string (getstring "\n Text string to change: "))
 (if (/= string "")
   (progn
     (setq texts (ssget "x" (list (cons 0 "TEXT") (cons 1 string))))
     (if texts
(progn
  (setq color (acad_colordlg 256 T 0))
  (if (/= color nil)
    (progn
      (if (= color 256)
 (setq color "ByLayer"))
      (if (= color 0)
 (setq color "ByBlock"))
      (command "chprop" texts "" "c" color "")
      (princ (strcat "\n Changed "
       (rtos (sslength texts))
       " text(s) with string >> "
       string
       " <<"))
      )
    (princ "\n Color not selected!")
    )
  )
(princ (strcat "\n Not find text(s) with string >> "
        string
        " <<"))
)
     )
   (princ "\n Type string to search!")
   )
 (princ)
)

type * for all strings

also the Qselect command could work...

Link to comment
Share on other sites

quick google :

 

 

; [url]https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-text-and-change-color/td-p/1974137[/url]
(defun c:cc  (/ string color texts) ;Change Color
 (setq string (getstring "\n Text string to change: "))
 (if (/= string "")
   (progn
     (setq texts (ssget "x" (list (cons 0 "TEXT") (cons 1 string))))
     (if texts
(progn
  (setq color (acad_colordlg 256 T 0))
  (if (/= color nil)
    (progn
      (if (= color 256)
 (setq color "ByLayer"))
      (if (= color 0)
 (setq color "ByBlock"))
      (command "chprop" texts "" "c" color "")
      (princ (strcat "\n Changed "
       (rtos (sslength texts))
       " text(s) with string >> "
       string
       " <<"))
      )
    (princ "\n Color not selected!")
    )
  )
(princ (strcat "\n Not find text(s) with string >> "
        string
        " <<"))
)
     )
   (princ "\n Type string to search!")
   )
 (princ)
)

type * for all strings

also the Qselect command could work...

 

 

no sir, i mean how can i change my code to select all text and change the color based on the value of the text...

the one you gave will actually make the process longer if i use "search"

Link to comment
Share on other sites

haven't got a drawing to test it on so untested :

(defun c:foo (/ ss hcol clr e)
 (if (setq ss (ssget "_X" (list '(0 . "TEXT"))))
   (foreach e (mapcar 'cadr (ssnamex ss))
     (setq hcol (atof (cdr (assoc 1 (entget e)))))
     (cond ((<= hcol 0.09)(setq clr 252))
    ((<= hcol 0.49)(setq clr 5))
    ((<= hcol 0.99)(setq clr 3))
    ((<= hcol 1.99)(setq clr 2))
    ((<= hcol 2.99)(setq clr 30))
    ((>= hcol 3)(setq clr 6)))
     (command "change" e "" "_p" "Color" clr "")
   )
 )
 (princ)
)

Link to comment
Share on other sites

Hi,

My attempt.

(defun c:foo (/ str int sel ent get lst)
 (and
   (setq str ""
         lst '(("0.09" 252) ("0.49" 5) ("0.99" 3)) ;; add your more desired of strings with colours here
         int -1
         sel (ssget
               "_X"
               (list
                 '(0 . "TEXT")
                 (cons
                   1
                   (apply
                     'strcat
                     (mapcar '(lambda (u) (setq str (strcat (car u) ",")))
                             lst
                     )
                   )
                 )
               )
             )
   )
   (while (setq ent (ssname sel (setq int (1+ int))))
     (entmod
       (append (setq get (entget ent))
               (list (cons 62 (cadr (assoc (cdr (assoc 1 get)) lst))))
       )
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...