robertbon Posted November 6, 2013 Posted November 6, 2013 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)) ) ) Quote
MSasu Posted November 6, 2013 Posted November 6, 2013 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))) ) ... Quote
robertbon Posted November 6, 2013 Author Posted November 6, 2013 Thank you Mircea, that works nicely. I noticed I had my greater/less thans the wrong way round! (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)) ) ) Quote
MSasu Posted November 6, 2013 Posted November 6, 2013 Glad to hear that my example it was useful to you! You're welcome! Quote
Recommended Posts
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.