DuanJinHui 发表于 2022-7-5 19:40:58

3DSolid颜色随机变化

我想更改3dsolid颜色(颜色不相同),但3dsolid对象太多(>300),
 
那么,可以使用lisp随机更改3DSolid颜色吗?(ACI),有可能吗?
 

ReMark 发表于 2022-7-5 19:50:30

是否要为300多个实体对象随机指定颜色?每个物体都会被指定一个唯一的颜色,还是你会使用有限的颜色范围?

DuanJinHui 发表于 2022-7-5 19:58:57

 
颜色可以重复。

ReMark 发表于 2022-7-5 20:05:13

你有没有想出一套你喜欢的颜色?

Tharwat 发表于 2022-7-5 20:11:54

你好
 
这是我的尝试
 

(defun c:test (/ ss i)
;;------------------------------------;;
;; Tharwat 17.06.2015                        ;;
;; Color 3dSolid objects randomly        ;;
;;------------------------------------;;
(if c c (setq c 1))
(if (setq ss (ssget "_:L" '((0 . "3DSOLID"))))
   (repeat (setq i (sslength ss))
   (entmod (append (entget (ssname ss (setq i (1- i))))
                     (list (cons 62 (rem c 255)))
                     )
             )
   (setq c (+ c 3))
   )
   )
(princ)
)

Lee Mac 发表于 2022-7-5 20:19:09

以下内容将为每个选定实体指定伪随机颜色:

(defun c:3dcol ( / i s )
   (if (setq s (ssget "_:L" '((0 . "3DSOLID"))))
       (repeat (setq i (sslength s))
         (vla-put-color (vlax-ename->vla-object (ssname s (setq i (1- i)))) (LM:randrange 1 255))
       )
   )
   (princ)
)

;; Rand-Lee Mac
;; PRNG implementing a linear congruential generator with
;; parameters derived from the book 'Numerical Recipes'

(defun LM:rand ( / a c m )
   (setq m   4294967296.0
         a   1664525.0
         c   1013904223.0
         $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
   )
   (/ $xn m)
)

;; Random in Range-Lee Mac
;; Returns a pseudo-random integral number in a given range (inclusive)

(defun LM:randrange ( a b )
   (fix (+ a (* (LM:rand) (- b a -1))))
)

(vl-load-com) (princ)

 
以上随机数函数来自我的网站。

DuanJinHui 发表于 2022-7-5 20:31:28

 
非常感谢你。塔瓦特
 
 
非常感谢你。李

Tharwat 发表于 2022-7-5 20:38:50

 
非常欢迎你。

Lee Mac 发表于 2022-7-5 20:41:57

没问题
页: [1]
查看完整版本: 3DSolid颜色随机变化