Jump to content

Would like to change Text Colour of numbers based on pre-set numeric range.


0misclose

Recommended Posts

Hi all,

 

I found a lisp which allows me to enter in a min and max value for a range which then selects the text (which are numeric values e.g. -0.031 or 0.02) which fall in that range. I can then change the colours of the selected numbers. As I have 5 different number ranges which I want to use on a consistent basis, I was wondering if it would be possible for someone to help create a lisp which does this all automatically. I could simply run the lisp with no need to enter the range values or colours as they are already set within the lisp.

 

The text ranges (inclusive) that I am using are as follows:

0.020+ = Red (1)

0.019 to 0.011 = Orange (40)

-0.010 to 0.010 = Green (3)

-0.011 to -0.019 = Light Blue (4)

-0.020 or less = Dark Blue (5)

 

This isn't super important to have but I just thought I'd ask the question to see if some magical Autocad wizard could put it together (I'm relatively new to Autocad).

 

Regardless, would appreciate any suggestions. Have a great day.

 

Link to comment
Share on other sites

6 hours ago, 0misclose said:

Hi all,

 

I found a lisp which allows me to enter in a min and max value for a range which then selects the text (which are numeric values e.g. -0.031 or 0.02) which fall in that range. I can then change the colours of the selected numbers. As I have 5 different number ranges which I want to use on a consistent basis, I was wondering if it would be possible for someone to help create a lisp which does this all automatically. I could simply run the lisp with no need to enter the range values or colours as they are already set within the lisp.

 

The text ranges (inclusive) that I am using are as follows:

0.020+ = Red (1)

0.019 to 0.011 = Orange (40)

-0.010 to 0.010 = Green (3)

-0.011 to -0.019 = Light Blue (4)

-0.020 or less = Dark Blue (5)

 

This isn't super important to have but I just thought I'd ask the question to see if some magical Autocad wizard could put it together (I'm relatively new to Autocad).

 

Regardless, would appreciate any suggestions. Have a great day.

 

 

hi

attach the file be better to modify it

Link to comment
Share on other sites

Hi 0miscolse give it a try . attached a dwg sample 

 

;************************************************************
;; inicia-dist-from-origin
 ;*****************************************************************
;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;;    Copyleft 1995-2021 by Gabriel Calos De Vit ; DEVITG@GMAIL.COM    
;;

(DEFUN C:CHG-CLR  (/
                   ACAD-OBJ
                   ADOC
                   TEXT
                   TEXT#
                   TEXT-OBJ-SS
                   TEXT-SS
                   )


  (VL-LOAD-COM)
  (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) 
  (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ))
  
  (SETQ TEXT-SS (SSGET "X"
                       (LIST (CONS 0 "TEXT")
                             (CONS 1 "-#.###,#.###")
                             )))

  (SETQ TEXT-OBJ-SS (VLA-GET-ACTIVESELECTIONSET ADOC))
  (VLAX-FOR TEXT-OBJ  TEXT-OBJ-SS
    (SETQ TEXT (VLA-GET-TEXTSTRING TEXT-OBJ))
    (SETQ TEXT# (ATOF TEXT))
    (COND
      ((> TEXT# 0.019) (VLA-PUT-COLOR TEXT-OBJ 1))
      ((> 0.020 TEXT# 0.010) (VLA-PUT-COLOR TEXT-OBJ 40))
      ((> 0.011 TEXT# -0.011) (VLA-PUT-COLOR TEXT-OBJ 3))
      ((> -0.010 TEXT# -0.019) (VLA-PUT-COLOR TEXT-OBJ 4))
      ((<= TEXT# -0.020) (VLA-PUT-COLOR TEXT-OBJ 5))
      ) ;end cond 
    ); end VLAX-FOR
  );end C:CHG-CLR

 

chag color as value.dwg chg color as value.LSP

Link to comment
Share on other sites

Annotative text whose size is affected by the Viewport Annotative Scale of it's Viewport and Mtext which could have the entire text size overridden or multiple portions of the text overridden in different sizes could make this lisp rather complicated.

Link to comment
Share on other sites

14 hours ago, devitg said:

Hi 0miscolse give it a try . attached a dwg sample 

 



;************************************************************
;; inicia-dist-from-origin
 ;*****************************************************************
;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;;    Copyleft 1995-2021 by Gabriel Calos De Vit ; DEVITG@GMAIL.COM    
;;

(DEFUN C:CHG-CLR  (/
                   ACAD-OBJ
                   ADOC
                   TEXT
                   TEXT#
                   TEXT-OBJ-SS
                   TEXT-SS
                   )


  (VL-LOAD-COM)
  (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) 
  (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ))
  
  (SETQ TEXT-SS (SSGET "X"
                       (LIST (CONS 0 "TEXT")
                             (CONS 1 "-#.###,#.###")
                             )))

  (SETQ TEXT-OBJ-SS (VLA-GET-ACTIVESELECTIONSET ADOC))
  (VLAX-FOR TEXT-OBJ  TEXT-OBJ-SS
    (SETQ TEXT (VLA-GET-TEXTSTRING TEXT-OBJ))
    (SETQ TEXT# (ATOF TEXT))
    (COND
      ((> TEXT# 0.019) (VLA-PUT-COLOR TEXT-OBJ 1))
      ((> 0.020 TEXT# 0.010) (VLA-PUT-COLOR TEXT-OBJ 40))
      ((> 0.011 TEXT# -0.011) (VLA-PUT-COLOR TEXT-OBJ 3))
      ((> -0.010 TEXT# -0.019) (VLA-PUT-COLOR TEXT-OBJ 4))
      ((<= TEXT# -0.020) (VLA-PUT-COLOR TEXT-OBJ 5))
      ) ;end cond 
    ); end VLAX-FOR
  );end C:CHG-CLR

 

chag color as value.dwg 50.06 kB · 1 download chg color as value.LSP 1.28 kB · 1 download

 

devitg thank you for that, it's almost perfect for what I want! 

 

My data has rounded values from one digit to 3 decimal places. e.g.  0, 0.1, 0.04, -0.066 (My mistake for not providing this information)

 

It appears that the lisp isn't working for single digit to two decimal place numbers (I could be mistaken). Regardless I really appreciate the help.

 

I modified the following line and it appears to work? (CONS 1 "-#.###,-#.##,-#.#,#,#.#,#.##,#.###")

 

I've attached an example DWG of some of the text that I am working with which I have already changed the colours of.

 

 

Cheers

 

TextColourChange.dwg

Edited by 0misclose
Additional Info
Link to comment
Share on other sites

13 hours ago, 0misclose said:

My data has rounded values from one digit to 3 decimal places. e.g.  0, 0.1, 0.04, -0.066 (My mistake for not providing this information)

 

This has to do with the selection set. This will select all text on the delta layer, and not only the ones with only 3 decimal places.

;************************************************************
;; inicia-dist-from-origin
 ;*****************************************************************
;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;;    Copyleft 1995-2021 by Gabriel Calos De Vit ; DEVITG@GMAIL.COM    
;;
(DEFUN C:CHG-CLR (/ ACAD-OBJ ADOC TEXT TEXT# TEXT-OBJ-SS TEXT-SS)
  (VL-LOAD-COM)
  (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT))
  (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ))
  (SETQ TEXT-SS (SSGET "X" '((0 . "TEXT") (8 . "DELTA"))))
  (SETQ TEXT-OBJ-SS (VLA-GET-ACTIVESELECTIONSET ADOC))
  (VLAX-FOR TEXT-OBJ TEXT-OBJ-SS
    (SETQ TEXT (VLA-GET-TEXTSTRING TEXT-OBJ))
    (SETQ TEXT# (ATOF TEXT))
    (COND
      ((> TEXT# 0.019) (VLA-PUT-COLOR TEXT-OBJ 1))
      ((> 0.020 TEXT# 0.010) (VLA-PUT-COLOR TEXT-OBJ 40))
      ((> 0.011 TEXT# -0.011) (VLA-PUT-COLOR TEXT-OBJ 3))
      ((> -0.010 TEXT# -0.019) (VLA-PUT-COLOR TEXT-OBJ 4))
      ((<= -0.031 TEXT# -0.020) (VLA-PUT-COLOR TEXT-OBJ 5))
    )  ;end cond
  )    ; end VLAX-FOR
)      ;end C:CHG-CLR

 

 

 

Link to comment
Share on other sites

How to select  all text from - 4 to  + 4 integer digits to 3 to 6  decimal digits 

Whit following example it will select 1 integer , to 3 decimal 

 (CONS 1 "-#.###,-#.##,-#.#,#,#.#,#.##,#.###")

Maybe it could be a simple way 

  • Like 1
Link to comment
Share on other sites

4 hours ago, devitg said:

How to select  all text from - 4 to  + 4 integer digits to 3 to 6  decimal digits 

Whit following example it will select 1 integer , to 3 decimal 


 (CONS 1 "-#.###,-#.##,-#.#,#,#.#,#.##,#.###")

Maybe it could be a simple way 

 

You might be interested in Roy's excellent contribution in this thread.

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