halam 发表于 2022-7-5 17:23:42

随机色数

大家好
 
 
我正在尝试更好地获得一个例程,它将帮助我获得一些对比度,以查看我在三维模型中的块(/层)定义是什么。
我的出发点是这段代码beneith,它将在1-255范围内为+1之后的层分配颜色。
该c值应在此范围内随机并四舍五入。这样,遵循逻辑部分的方式得到了更大的对比度(出于工程目的…)
 
 
有人有好的方法吗?
 
 
(编辑:使用LM的完整代码:…&ROY_043方法)
 


; random layer colors
;; 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 )
   (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b))))))
)


(defun c:Lcolor ()
(vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
   (if
   (and
       (= :vlax-false (vla-get-lock x))
       (= :vlax-false (vla-get-freeze x))
       (not (wcmatch (vla-get-name x) "*|*"))
   )
   (vla-put-color x (LM:randrange 10 249))
   )
)
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
(princ)
)

(vl-load-com) (princ)

Lee Mac 发表于 2022-7-5 17:29:19

您可以使用我的随机范围内函数,例如:
(defun c:lcolor nil
   (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
       (vla-put-color x (LM:randrange 10 249))
   )
   (princ)
)
(vl-load-com) (princ)

halam 发表于 2022-7-5 17:37:40

太棒了!(如果你不介意换些颜色……)

Grrr 发表于 2022-7-5 17:41:00

好主意,李的动作很棒!

halam 发表于 2022-7-5 17:47:28

谢谢Grrr先生。我也这么想
用户应考虑将此代码与当前保存的layerstate结合使用。
提出一个问题:“你想保存当前状态吗?”
 
我只是有点更好的想法比真正聪明的编码。。。无论如何

tzframpton 发表于 2022-7-5 17:53:24

很酷的东西,汉斯。

halam 发表于 2022-7-5 17:58:20

思考并努力使这一切顺利进行
因此,它不会影响锁定、冻结或外部参照的层(?)
 
 



;; CAB
;; https://www.theswamp.org/index.php?topic=888.msg11892#msg11892
;;


;;;Returns T if Locked
;;;      nil if Unlocked or not found
;;;      nil if lname is not a string
(defun islayerlocked (lname / entlst)
(and (= 'str (type lname))
      (setq entlst (tblsearch "LAYER" lname))
      (= 4 (logand 4 (cdr (assoc 70 entlst))))
)
)

;;;Returns T if Frozen
(defun islayerfrozen (lname / entlst)
(and (= (type lname) 'str)
      (setq entlst (tblsearch "layer" lname))
      (= 1 (logand 1 (cdr (assoc 70 entlst))))
)
) ; end defun


Grrr 发表于 2022-7-5 18:06:12

 
对于锁定层,请尝试以下操作:
(defun c:test nil
(vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (if (= (vla-get-Lock x) :vlax-true)
                (progn
                        (vla-put-lock x :vlax-false)
                        (vla-put-color x (LM:randrange 10 249))
                        (vla-put-lock x :vlax-true)
                )
                (vla-put-color x (LM:randrange 10 249))
        )
)
(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
(princ)
)
(vl-load-com) (princ)

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

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

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

halam 发表于 2022-7-5 18:12:09

它不起作用,这也不起作用,我知道我认为会起作用。。
 
 

(defun c:lcolor nil
(vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(if (= (vla-get-Lock x) :vlax-true) () (
(progn (
   (vla-put-lock x :vlax-false)
   (vla-put-color x (LM:randrange 10 249))
   (vla-put-lock x :vlax-true)
))
(vla-put-color x (LM:randrange 10 249))
)
)
(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
(princ)
)
(vl-load-com) (princ)
)

 
 
返回:“错误:无函数定义:nil”

Roy_043 发表于 2022-7-5 18:14:49

(defun c:lcolor ()
(vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
   (if
   (and
       (= :vlax-false (vla-get-lock x))
       (= :vlax-false (vla-get-freeze x))
       (not (wcmatch (vla-get-name x) "*|*"))
   )
   (vla-put-color x (LM:randrange 10 249))
   )
)
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
(princ)
)
页: [1] 2
查看完整版本: 随机色数