183017064 发表于 7 天前

发个随机改颜色的代码——娱乐用

本帖最后由 183017064 于 2025-4-14 11:03 编辑

(defun RandomColor (/ ent color-list) ; 随机颜色命令
    (setq color-list '(
      40    ;
      201   ;
      11    ;
      110   ;
      160   ;
      212   ;
    )) ; 预置颜色
    (while (setq ent (car (entsel "\n选实体: ")))
      (entmod            ; 关键修改语句
            (append
                (entget ent)
                (list (cons 62 (nth (rem (getvar "MILLISECS") (length color-list)) color-list))) (defun RandomColorall (/ ent) ; 随机颜色命令
    (while (setq ent (car (entsel "\n选实体: ")))
      (entmod
            (append
                (entget ent)
                (list (cons 62 (1+ (rem (getvar "MILLISECS") 255))))
            )
      )
    )
    (princ)
)作为一个子程序用,当选用一个元素作为基准的话,可以清楚的表达一下。实用性可有可无,添加一点制图的趣味性。(PS:个人认为)

yjwht 发表于 7 天前

都试了,前者在color-list中随机颜色,后者在1~255中随机颜色。

magicheno 发表于 7 天前

感谢大佬分享

MZ_li 发表于 6 天前

感谢大佬分享

jkop 发表于 6 天前

娱乐性,还能兼做入门学习用!

season_88 发表于 6 天前

谢谢大佬分享

183017064 发表于 5 天前

jkop 发表于 2025-4-12 10:16
娱乐性,还能兼做入门学习用!

我也没想那么多,就是想,当我们选择一个元素作为基准的时候,能不能清楚一点。
页: [1]
查看完整版本: 发个随机改颜色的代码——娱乐用