Skip to main content
Participant
December 30, 2010
Question

toggle layer visibility

  • December 30, 2010
  • 2 replies
  • 8231 views

Hello,

I need one keyboard shortcut that toggles visibility of one of layers.

I paint and need to toggle on and off one layer below (layer with a reference picture, not one i paint on). with a shortcut painting process will be not break as with case click at icon.

tried to make toggle layer visibility with actions unfortunately with no success.

it is possibility to toggle active layer visibility by add shortcut in keyboard shortcuts preferences  but here it going not about active layer.

I have no experience with scripting.

thank you!

This topic has been closed for replies.

2 replies

rcraighead
Legend
October 12, 2018

This thread has helped me. I only needed to toggle a named layer. This is the Javascript that works for me. Perhaps someone else will find it useful.

app.activeDocument.layers.getByName('LayerNameHere').visible ^= 1;
Kukurykus
Legend
October 12, 2018

Good to know '^=' toggles visibility.

Inspiring
December 30, 2010

If I understand what you are asking the script below will toggle the layer visibility of the layer below the active/selected layer. It works with layerSets. If the selected layer is at the bottom of the stack/set, the script does nothing.

var curentLayer = app.activeDocument.activeLayer;
var curentParent = curentLayer.parent;
var currentIndex = getLayerIndex( curentParent, curentLayer );
if(currentIndex != (curentParent.artLayers.length-1)){
    curentParent.artLayers[currentIndex+1].visible= !curentParent.artLayers[currentIndex+1].visible;
}
function getLayerIndex( parent, layer ){
    for(var i=0;i<parent.artLayers.length;i++){
        if(parent.artLayers==layer) return i;
    }
};

Participant
December 30, 2010

Exactly what i need! works great! Thank you!!

it is possible to have some additional functionality like that: script check if layer named "Ref" exist and if yes  toggles its visibility ?

many thanks!

Inspiring
December 30, 2010

Do you mean you only want to toggle the layer below the selected layer if the layer below's name is 'Ref'?

Or do you mean you want to toggle the layer named 'Ref' no matter where it is in a stack?