Author Topic: Lighten layers' colors  (Read 147 times)

0 Members and 1 Guest are viewing this topic.

w64bit

  • Newt
  • Posts: 49
Lighten layers' colors
« on: June 06, 2021, 10:05:34 AM »
I am using black background and with this script I lighten darker layer colors.
- first color row in Color window will be assigned the next row below
- last row row in Color window will be assigned the next row above
Is there any way to slim the code, without using too many lisp functions?
Code: [Select]
(vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (= 18 (vla-get-Color layer))(vla-put-Color layer 16))
(if (= 28 (vla-get-Color layer))(vla-put-Color layer 26))
(if (= 38 (vla-get-Color layer))(vla-put-Color layer 36))
(if (= 48 (vla-get-Color layer))(vla-put-Color layer 46))
(if (= 58 (vla-get-Color layer))(vla-put-Color layer 56))
(if (= 68 (vla-get-Color layer))(vla-put-Color layer 66))
(if (= 78 (vla-get-Color layer))(vla-put-Color layer 76))
(if (= 88 (vla-get-Color layer))(vla-put-Color layer 86))
(if (= 98 (vla-get-Color layer))(vla-put-Color layer 96))
(if (= 108 (vla-get-Color layer))(vla-put-Color layer 106))
(if (= 118 (vla-get-Color layer))(vla-put-Color layer 116))
(if (= 128 (vla-get-Color layer))(vla-put-Color layer 126))
(if (= 138 (vla-get-Color layer))(vla-put-Color layer 136))
(if (= 148 (vla-get-Color layer))(vla-put-Color layer 146))
(if (= 158 (vla-get-Color layer))(vla-put-Color layer 156))
(if (= 168 (vla-get-Color layer))(vla-put-Color layer 166))
(if (= 178 (vla-get-Color layer))(vla-put-Color layer 176))
(if (= 188 (vla-get-Color layer))(vla-put-Color layer 186))
(if (= 198 (vla-get-Color layer))(vla-put-Color layer 196))
(if (= 208 (vla-get-Color layer))(vla-put-Color layer 206))
(if (= 218 (vla-get-Color layer))(vla-put-Color layer 216))
(if (= 228 (vla-get-Color layer))(vla-put-Color layer 226))
(if (= 238 (vla-get-Color layer))(vla-put-Color layer 236))
(if (= 248 (vla-get-Color layer))(vla-put-Color layer 246))
(if (= 19 (vla-get-Color layer))(vla-put-Color layer 17))
(if (= 29 (vla-get-Color layer))(vla-put-Color layer 27))
(if (= 39 (vla-get-Color layer))(vla-put-Color layer 37))
(if (= 49 (vla-get-Color layer))(vla-put-Color layer 47))
(if (= 59 (vla-get-Color layer))(vla-put-Color layer 57))
(if (= 69 (vla-get-Color layer))(vla-put-Color layer 67))
(if (= 79 (vla-get-Color layer))(vla-put-Color layer 77))
(if (= 89 (vla-get-Color layer))(vla-put-Color layer 87))
(if (= 99 (vla-get-Color layer))(vla-put-Color layer 97))
(if (= 109 (vla-get-Color layer))(vla-put-Color layer 107))
(if (= 119 (vla-get-Color layer))(vla-put-Color layer 117))
(if (= 129 (vla-get-Color layer))(vla-put-Color layer 127))
(if (= 139 (vla-get-Color layer))(vla-put-Color layer 137))
(if (= 149 (vla-get-Color layer))(vla-put-Color layer 147))
(if (= 159 (vla-get-Color layer))(vla-put-Color layer 157))
(if (= 169 (vla-get-Color layer))(vla-put-Color layer 167))
(if (= 179 (vla-get-Color layer))(vla-put-Color layer 177))
(if (= 189 (vla-get-Color layer))(vla-put-Color layer 187))
(if (= 199 (vla-get-Color layer))(vla-put-Color layer 197))
(if (= 209 (vla-get-Color layer))(vla-put-Color layer 207))
(if (= 219 (vla-get-Color layer))(vla-put-Color layer 217))
(if (= 229 (vla-get-Color layer))(vla-put-Color layer 227))
(if (= 239 (vla-get-Color layer))(vla-put-Color layer 237))
(if (= 249 (vla-get-Color layer))(vla-put-Color layer 247))
(if (= 250 (vla-get-Color layer))(vla-put-Color layer 7))
(princ))

kpblc

  • Bull Frog
  • Posts: 379
Re: Lighten layers' colors
« Reply #1 on: June 06, 2021, 10:16:32 AM »
Only idea (30 seconds to create):
(if (or (member (vla-get-color layer) '(18 28 38 48 58 68 78 88 98 108 118 128 138 148 158 168 178 188 198 208 218 228 238 248))
(member (vla-get-color layer) '(19 29 39 49 59 69 79 89 99 109 119 129 139 149 159 169 179 189 199 209 219 229 239 249))
)
(vla-put-color layer (- (vla-get-color layer) 2)))
Sorry for my English.

kpblc

  • Bull Frog
  • Posts: 379
Re: Lighten layers' colors
« Reply #2 on: June 06, 2021, 10:40:46 AM »
I thought you can recognize - change all your if's to my code and check how it works.
Code - Auto/Visual Lisp: [Select]
  1. (defun t1 (/ adoc)
  2.     (if (or (member (vla-get-color layer)
  3.                     '(18 28 38 48 58 68 78 88 98 108 118 128 138 148 158 168 178 188 198 208 218 228 238 248)
  4.             ) ;_ end of member
  5.             (member (vla-get-color layer)
  6.                     '(19 29 39 49 59 69 79 89 99 109 119 129 139 149 159 169 179 189 199 209 219 229 239 249)
  7.             ) ;_ end of member
  8.         ) ;_ end of or
  9.       (vla-put-color layer (- (vla-get-color layer) 2))
  10.     ) ;_ end of if
  11.   ) ;_ end of vlax-for
  12.   (vla-endundomark adoc)
  13.   (princ)
  14. ) ;_ end of defun
Sorry for my English.

w64bit

  • Newt
  • Posts: 49
Re: Lighten layers' colors
« Reply #3 on: June 06, 2021, 01:57:36 PM »
Thank you.

roy_043

  • Water Moccasin
  • Posts: 1870
  • BricsCAD 18
Re: Lighten layers' colors
« Reply #4 on: June 06, 2021, 02:44:05 PM »
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun test (/ doc)
  3.   (vlax-for lay (vla-get-layers doc)
  4.     (setq aci (vla-get-color lay))
  5.     (cond
  6.       ((= aci 250)
  7.         (vla-put-color lay 7)
  8.       )
  9.       ((< aci 18)
  10.         nil
  11.       )
  12.       ((vl-position (rem aci 10) '(8 9))
  13.         (vla-put-color lay (- aci 2))
  14.       )
  15.     )
  16.   )
  17.   (princ)
  18. )