Jump to content

Recommended Posts

Posted

I have a drawing with many level values (as text objects) on it. I want to use entmod to change the colour of the text object depending on whether it is above or below certain levels.

 

I need to replace (print "red") and (print "green") lines with entmod that does this - can someone help me finish this lisp routine please?

 


(defun c:levbound ()
;ask for lower and upper bounds
(setq lower (getreal "\nLower bound...?"))
(setq upper (getreal "\nUpper bound...?"))
;select text objects to be evaluated
(setq ss (ssget '((0 . "TEXT"))))
(setq l (sslength ss))
(setq c 0)
;evaluate each text object
(while (/= c l)
 (setq ent (ssname ss c))
 (setq elist (entget ent))
 (setq txt (cdr (assoc 1 elist)))
 (setq val (atof txt))
 ;if value lower than the lower bound
 (if (< lower val)
  ;***then change text object colour to red***
  (print "red")
  ;else, is it higher than the upper bound?
   (if (> upper val)
   ;***then change text object colour to green***
   (print "green")
   )
 )
(setq c (+ 1 c)) 
)
)

Posted

The color is stored under DXF code 62; you will need to check if isn't currently set as ByLayer.

(if (< lower val)
;***then change text object colour to red***
(progn
 (print "red")
 (entmod (if (assoc 62 elist)
          (subst '(62 . 1) (assoc 62 elist) elist)
          (cons  '(62 . 1) elist)))
)
...

Posted

Thank you Mircea, that works nicely.

 

I noticed I had my greater/less thans the wrong way round! :oops:

 


(defun c:levbnd ()
;ask for lower and upper bounds
(setq lower (getreal "\nLower bound...?"))
(setq upper (getreal "\nUpper bound...?"))
;select text objects to be evaluated
(setq ss (ssget '((0 . "TEXT"))))
(setq l (sslength ss))
(setq c 0)
;evaluate each text object
(while (/= c l)
 (setq ent (ssname ss c))
 (setq elist (entget ent))
 (setq txt (cdr (assoc 1 elist)))
 (setq val (atof txt))
 ;if value lower than the lower bound
 (if (< val lower )
  ;then change text object colour to red
   (entmod (if (assoc 62 elist)
   (subst '(62 . 1) (assoc 62 elist) elist)
   (cons  '(62 . 1) elist)))
  ;else, is it higher than the upper bound?
   (if (> val upper )
  ;then change text object colour to red
    (entmod (if (assoc 62 elist)
    (subst '(62 . 1) (assoc 62 elist) elist)
    (cons  '(62 . 1) elist)))
   )
 )
(setq c (+ 1 c)) 
)
)

Posted

Glad to hear that my example it was useful to you! You're welcome!

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