Hide and show the layer?

welcome everybody.
I want when the button is pressed for the first time, we hide the layer, and when the same button is pressed again, the layer is displayed. Can you help with that .

Greetings :pray:
Mohamed Fathy…

you can toggle layer visibility by reversing it’s current .visible property

assuming you have the layer reference stored in variable called layer you can try the following:

layer.visible = !layer.visible

the “exclamation point” (!) used before layer.visible will turn true into false and vice versa.

ofcourse you’ll need to run your code in modal state (executeAsModal)

the following example will toggle visibility of current active layer:

const { app, core: { executeAsModal } } = require("photoshop");

executeAsModal(() => {
    let layer = app.activeDocument.activeLayers[0];
    layer.visible = !layer.visible

Thank you Maher, it works like magic…
cheers… :wine_glass:
Greetings :pray:
Mohamed Fathy…

1 Like

Please remember to mark answer as a solution if it solves your problem. This helps others navigate the forum