Author Topic: Set Layer Transparency  (Read 3641 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Set Layer Transparency
« on: January 01, 2017, 05:51:23 PM »
Hi guys and happy new year!
Ontopic:
Refering to this thread.
I've just "found" a vanilla way about setting the layer transparency, and heres an example to assign a value of 25 % transparency on the current layer:

Code - Auto/Visual Lisp: [Select]
  1.   (setq enx
  2.     (append
  3.       (entget (tblobjname "LAYER" (getvar 'clayer)))
  4.       (list (list -3 (cons "AcCmTransparency" (list (cons 1071 33554623))))); 25 %
  5.     )
  6.   )
  7. )
  8. (entupd (cdr (assoc -1 enx)))

Well yeah, it works simple as that, by appending an xdata to the layer's elist.

The problem is that I have no idea about bit handling and I'm wondering could anyone reverse engineer this part of LM's suggestion in that thread:
Code - Auto/Visual Lisp: [Select]
  1. (fix (- 100 (/ (logand trn -33554433) 2.55)))
So it would be possible to write a subfunction that accepts integer in 0-90 range to set the transparency on layer x (without command-calls). :idea:
P.S. I know its doable with an assoc list, but the code may be less-effectively written.
« Last Edit: January 01, 2017, 06:00:52 PM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Set Layer Transparency
« Reply #1 on: January 01, 2017, 06:23:10 PM »
Here are my functions for transparency conversion:
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:trans->dxf ( x )
  2.     (logior (fix (* 2.55 (- 100 x))) 33554432)
  3. )
  4. (defun LM:dxf->trans ( x )
  5.     (fix (- 100 -1e-8 (/ (logand x (~ 33554432)) 2.55)))
  6. )

Getting/Setting Layer Transparency:
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:setlayertransparency ( lay trn / ent )
  2.     (if (setq ent (tblobjname "layer" lay))
  3.         (progn
  4.             (regapp "accmtransparency")
  5.             (entmod
  6.                 (append (entget ent)
  7.                     (list
  8.                         (list -3
  9.                             (list "accmtransparency"
  10.                                 (cons 1071 (LM:trans->dxf trn))
  11.                             )
  12.                         )
  13.                     )
  14.                 )
  15.             )
  16.         )
  17.     )
  18. )
  19. (defun LM:getlayertransparency ( lay / ent dxf )
  20.     (if (and (setq ent (tblobjname "layer" lay))
  21.              (setq dxf (cdr (assoc 1071 (cdadr (assoc -3 (entget ent '("accmtransparency")))))))
  22.         )
  23.         (LM:dxf->trans dxf)
  24.     )
  25. )

Where entity transparency is concerned, use DXF group 440 with 0 for ByLayer & 16777216 for ByBlock.
« Last Edit: January 01, 2017, 06:26:37 PM by Lee Mac »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Set Layer Transparency
« Reply #2 on: January 01, 2017, 06:53:42 PM »
This is awesome, certainly a good start for 2017 !
Thanks alot Lee, wishing you a benefitable and healthy year!
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Set Layer Transparency
« Reply #3 on: January 01, 2017, 07:15:23 PM »
You're most welcome Grrr1337 - all the best for 2017 to you too.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Set Layer Transparency
« Reply #4 on: January 02, 2017, 03:23:52 AM »
Hi,

What about simply doing:
Code - Auto/Visual Lisp: [Select]
  1. (setpropertyvalue (getvar 'clayer) "Transparency" 25)

Happy new year.
Speaking English as a French Frog

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: Set Layer Transparency
« Reply #5 on: January 02, 2017, 03:29:44 AM »
Hi,

What about simply doing:
Code - Auto/Visual Lisp: [Select]
  1. (setpropertyvalue (getvar 'clayer) "Transparency" 25)

Happy new year.


:)

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Set Layer Transparency
« Reply #6 on: January 02, 2017, 05:04:36 AM »
My conversion functions:
Code - Auto/Visual Lisp: [Select]
  1. ; (KGA_Sys_Transparency_Num_To_Perc 33554661) => 0.1 (= 10%)
  2. ; (KGA_Sys_Transparency_Num_To_Perc (cdr (assoc 440 (entget (car (entsel))))))
  3. (defun KGA_Sys_Transparency_Num_To_Perc (num)
  4.   (* 0.01 (fix (/ (- 33554687 num) 2.55)))
  5. )
  6.  
  7. ; (KGA_Sys_Transparency_Perc_To_Num 0.1) => 33554661
  8. (defun KGA_Sys_Transparency_Perc_To_Num (perc)
  9.   (fix (- 33554687 (* perc 255)))
  10. )

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Set Layer Transparency
« Reply #7 on: January 02, 2017, 05:39:36 AM »
Hi,

What about simply doing:
Code - Auto/Visual Lisp: [Select]
  1. (setpropertyvalue (getvar 'clayer) "Transparency" 25)

Happy new year.

Thanks Gile,
Actually I tried something similar before and I thought it didn't worked, since I didn't saw any graphical changes in model space.
Just gave it a second shot, and the layer properties manager confirms that the transparency is changed!
BTW setpropertyvalue requires the layer's ename (not the actual name):
Code - Auto/Visual Lisp: [Select]
  1. _$ (setpropertyvalue (tblobjname "LAYER" (getvar 'clayer)) "Transparency" 60)
  2. nil
  3.  
  4. _$ (setpropertyvalue (getvar 'clayer) "Transparency" 25)
  5.  
  6. Error: ADS request error
  7. _1$

Sooo.. another subfunction is created:
Code - Auto/Visual Lisp: [Select]
  1. ; (SetLayerTransparency (getvar 'clayer) 90)
  2. (defun SetLayerTransparency ( LayerName Transparency / lyr )
  3.   (and
  4.     (<= 0 Transparency 90)
  5.     (setq lyr (tblobjname "LAYER" LayerName))
  6.     (not (setpropertyvalue lyr "Transparency" Transparency))
  7.     (not (entupd lyr))
  8.   )
  9. )

For the pure Visual way one might dig here (not sure what method must be invoked):
Code - Auto/Visual Lisp: [Select]

Cheers guys! 8)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Set Layer Transparency
« Reply #8 on: January 04, 2017, 03:21:55 PM »
Hi,

What about simply doing:
Code - Auto/Visual Lisp: [Select]
  1. (setpropertyvalue (getvar 'clayer) "Transparency" 25)

Happy new year.
Whoa. When were setpropertyvalue / getpropertyvalue introduced?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Set Layer Transparency
« Reply #9 on: January 04, 2017, 04:47:03 PM »
Whoa. When were setpropertyvalue / getpropertyvalue introduced?
Its not the first time that Gile writes/suggest about them. For example in this thread.
Heres the thread where he spreads the word.  :-)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Set Layer Transparency
« Reply #10 on: January 04, 2017, 04:58:14 PM »
Whoa. When were setpropertyvalue / getpropertyvalue introduced?
Its not the first time that Gile writes/suggest about them. For example in this thread.
Heres the thread where he spreads the word.  :-)
*quickly deletes post #4 from thread* How did I miss that one?!?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox