Jump to content

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)))

Share this post


Link to post
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...

Share this post


Link to post
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"

Share this post


Link to post
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)
)

Share this post


Link to post
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)
)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×