sunil_b_v Posted May 8, 2012 Posted May 8, 2012 Is there any way to colorize different layers randomly? I wish to assign different colors to different layers. Please help. Sunil Quote
ReMark Posted May 8, 2012 Posted May 8, 2012 The topic has been covered previously. Look at the second and third posts in the following thread. http://www.cadtutor.net/forum/showthread.php?20380-LISP-for-assigning-layer-color Quote
Tharwat Posted May 8, 2012 Posted May 8, 2012 One way ..... (defun c:Test (/ i l obj) ;;; Tharwat 08. MAy. 2012 ;;; (setq i 1) (while (setq l (tblnext "LAYER" (null l))) (entmod (subst (cons 62 i) (assoc 62 (setq obj (entget (tblobjname "LAYER" (cdr (assoc 2 l)))))) obj ) ) (if (eq i 255) (setq i 1) (setq i (1+ i)) ) ) (princ) ) Quote
MSasu Posted May 8, 2012 Posted May 8, 2012 Since you are looking to assign the colors randomly, I suggest you to check the DOS_RANDOM function from McNeel's DOSLib pack: (rem (dos_random) 255) Quote
teknomatika Posted May 9, 2012 Posted May 9, 2012 Eventually it might help, indicating the number of the first color and then a loop with a number of increment. Quote
VVA Posted May 9, 2012 Posted May 9, 2012 Another variant ;;; ************************************************************************ ;; * Library DWGruLispLib http://forum.dwg.ru/showthread.php?t=15691 * ;; * * ;; * _dwgru-Random * ;; * * ;; Based vk_RandNum * ;; Http://www.caduser.ru/forum/index.php?PAGE_NAME=read&FID=23&TID=32763 * ;; * * ;; * * ;; * 07.12.2007 version 0001. Revision Vladimir Azarko (VVA) * ;; * 21.07.2008 version 0002. Revision Vov.Ka * ;; http://forum.dwg.ru/showpost.php?p=798277&postcount=9 * ;;; ************************************************************************ (defun _dwgru-random (/ modulus multiplier increment) ;;; Generate a random real number between 0 and 1 ;;; Use a global variable *DWGRU_SEED* (if (not *DWGRU_SEED*) (setq *DWGRU_SEED* (getvar "DATE")) ) (setq modulus 65536 multiplier 25173 increment 13849 *DWGRU_SEED* (rem (+ (* multiplier *DWGRU_SEED*) increment) modulus)) (/ *DWGRU_SEED* modulus) ) ;;; ************************************************************************ ;;; * ;;; * ;;; * dwgru-random-range http://forum.dwg.ru/showthread.php?t=15691 ;;; * ;;; * 07/12/2007 Версия 0001. Редакция Владимир Азарко (VVA) ;;; ************************************************************************ (defun dwgru-random-range (Minnum Maxnum ) ;;; Generate a random number from a specified range of integers ;;; Uses the library _dwgru-Random ;;; Parameters: ;;; Minnum - the smallest integer ;;; Maxnum - the maximum integer ;;; Return: An integer in the range specified ;;; Use: ;| (dwgru-random-range 1 256) (dwgru-random-range 1 15) |; ;(- Maxnum (atoi (rtos (* (- Maxnum Minnum) (_dwgru-num-random)) 2 0))) ;_Comment VVA 07.12.2007 ;;;Comment VVA http://forum.dwg.ru/showpost.php?p=798277&postcount=9 ;;;(- Maxnum (fix (* (- Maxnum Minnum) (_dwgru-random)))) ;_Add VVA 07.12.2007 Так наверное быстрее ;;; (- Maxnum (fix (* (- Maxnum Minnum -1) (_dwgru-random)))) ;;;Vov.ka http://forum.dwg.ru/showpost.php?p=798277&postcount=9 ) (defun c:Test (/ l obj) (while (setq l (tblnext "LAYER" (null l))) (entmod (subst (cons 62 (dwgru-random-range 1 255)) (assoc 62 (setq obj (entget (tblobjname "LAYER" (cdr (assoc 2 l)))))) obj ) ) ) (princ) ) Quote
David Bethel Posted May 9, 2012 Posted May 9, 2012 Since you are looking to assign the colors randomly, I suggest you to check the DOS_RANDOM function from McNeel's DOSLib pack: (rem (dos_random) 255) Watch out for a zero return from random or (rem) calls. -David Quote
Stefan BMR Posted May 10, 2012 Posted May 10, 2012 Using dos_random (vlax-map-collection (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ) (function (lambda (x) (vla-put-Color x (1+ (rem (dos_random) 254))) ) ) ) Quote
irneb Posted May 10, 2012 Posted May 10, 2012 Or using my own random & changing the layer's RGB colours: (vl-load-com) (defun Random (seed /) (if (not seed) (setq seed (if *random:seed* *random:seed* (setq *random:seed* (getvar "DATE")))) (setq *random:seed* seed)) (setq seed (rem (+ (* 25173 seed) 13849) 65536) *random:seed* seed) (/ seed 65536)) (defun c:RandomLayerColour (/ col) (vlax-for lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (setq col (vla-get-TrueColor lay)) (apply 'vla-SetRGB (cons col (mapcar '(lambda (n) (fix (* n 255))) (list (random nil) (random nil) (random nil))))) (vla-put-TrueColor lay col)) (princ)) 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.