robertbon 发表于 2022-7-6 00:04:29

Entmod更改文本对象c

我有一个有许多级别值(作为文本对象)的图形。我想使用entmod来改变文本对象的颜色,这取决于它是高于还是低于某些级别。
 
我需要用entmod替换(打印“红色”)和(打印“绿色”)行,这样做-有人能帮我完成这个lisp例程吗?
 


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

MSasu 发表于 2022-7-6 00:31:41

颜色存储在DXF代码62下;您需要检查当前是否未设置为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)))
)
...

robertbon 发表于 2022-7-6 00:47:13

谢谢你,米尔恰,效果很好。
 
我注意到我的大于/小于错误!
 


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

MSasu 发表于 2022-7-6 01:05:35

很高兴听到我的例子对你有用!不客气!
页: [1]
查看完整版本: Entmod更改文本对象c