Jump to content
Robinbb

Color coding text

Recommended Posts

Robinbb

Hello Everyone!

 

I am using vanilla AutoCAD 2017. I have recently done a hydrographic survey, so I have a drawing full of depths (text). Wondering if anyone can point me to a lisp routine that can color code the text based on a range. For example any depths between 10 and 20 is green or any depths between 20 and 30 are red.

 

Thanks in advance.

Share this post


Link to post
Share on other sites
dlanorh
30 minutes ago, Robinbb said:

Hello Everyone!

 

I am using vanilla AutoCAD 2017. I have recently done a hydrographic survey, so I have a drawing full of depths (text). Wondering if anyone can point me to a lisp routine that can color code the text based on a range. For example any depths between 10 and 20 is green or any depths between 20 and 30 are red.

 

Thanks in advance.

 

Simple enough, what layer is the text on, is there any other text on this layer, is the depth denoted with minus sign and is it just Text or is MText or both?

Share this post


Link to post
Share on other sites
Robinbb
16 minutes ago, dlanorh said:

 

Simple enough, what layer is the text on, is there any other text on this layer, is the depth denoted with minus sign and is it just Text or is MText or both?

 

No other text is on the layer and the depths are Text and denoted with a minus sign and on layer "$SHTXT_GRID"

Share this post


Link to post
Share on other sites
dlanorh
36 minutes ago, Robinbb said:

 

No other text is on the layer and the depths are Text and denoted with a minus sign and on layer "$SHTXT_GRID"

 

 

OK, try this

 

;; Autocad colors 1 = red 2 = yellow 3 = green 4 = cyan 5 = blue 6 = magenta 7 = white
(defun c:depthtext ( / ss cnt obj depth)
  (setq ss (ssget "_X" '((0 . "TEXT")(8 . "$SHTXT_GRID" ))))
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))
                  depth (atof (vlax-get-property obj 'textstring))
            )
            (cond ( (< -10.0 depth 0.0)) ; do nothing
                  ( (< -20.0 depth -10.0) (vlax-put-property obj 'color 3))   ; 3 is Green
                  ( (< -30.0 depth -20.0) (vlax-put-property obj 'color 1))   ; 1 is Red
                  ( (< -40.0 depth -30.0))   ; do nothing
            )
          )
        )
  )
)

Any problems let me know. I'll be around for the next couple of hours

 

Share this post


Link to post
Share on other sites
Robinbb
6 minutes ago, dlanorh said:

 

 

OK, try this

 


;; Autocad colors 1 = red 2 = yellow 3 = green 4 = cyan 5 = blue 6 = magenta 7 = white
(defun c:depthtext ( / ss cnt obj depth)
  (setq ss (ssget "_X" '((0 . "TEXT")(8 . "$SHTXT_GRID" ))))
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))
                  depth (atof (vlax-get-property obj 'textstring))
            )
            (cond ( (< -10.0 depth 0.0)) ; do nothing
                  ( (< -20.0 depth -10.0) (vlax-put-property obj 'color 3))   ; 3 is Green
                  ( (< -30.0 depth -20.0) (vlax-put-property obj 'color 1))   ; 1 is Red
                  ( (< -40.0 depth -30.0))   ; do nothing
            )
          )
        )
  )
)

Any problems let me know. I'll be around for the next couple of hours

 

 

Thank you very much, this was exactly what I am looking for, I can work with this and edit it.

Share this post


Link to post
Share on other sites
dlanorh

Excellent. Glad I could help. 👍

Share this post


Link to post
Share on other sites
BIGAL

Has been asked before, some options number of color ranges determines the elevation range. Color is 1-255 / range for approx color number.

 

If you have access to CIV3D "Rainbow" contour display is built in.

Share this post


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

×   Pasted as rich text.   Paste as plain text instead

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