• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

layer group visibility toggle

Participant ,
Oct 01, 2014 Oct 01, 2014

Copy link to clipboard

Copied

With the help of this forum I obtained a script  which toggles the visibility of a specific layer without  selecting the layer.

I would like to find out if the same functionality can be achieved for a layer group.

In other words can script toggle the visibility of a layer group with out actually selecting the layer group?

I understand some parts of Photoshop are not scriptable and wan to make sure this isn't one of them before I embark in creating the script.

TOPICS
Actions and scripting

Views

2.3K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Oct 02, 2014 Oct 02, 2014

I have a script that does what you need. Can't remember if I obtained it from here, but I do know that the scripting guys in here are geniuses and can help you out with almost anything. That said, here is the script that you need. All you need to do is replace the three "Insert Layer Name Here" portions with the name of the layer you wish to toggle on/off. Don't thank me, thank whoever wrote it, (most likely someone here)

var targetID = getLayerIDByName('Insert Layer Name here');

if(undefin

...

Likes

Translate

Translate
Community Expert ,
Oct 02, 2014 Oct 02, 2014

Copy link to clipboard

Copied

As far as AM code is concerned Groups are Layers, too, so what is the problem?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 02, 2014 Oct 02, 2014

Copy link to clipboard

Copied

No problem at all. Trying to figure out an approach to create the script.

I can get the AM code from the script listener for the layer group visibility toggle.

Make a function with the AM code, declare a variable for the layer group, 

use an if statement to check the visibility of the layer group.

If visibility is true then do the opposite.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 02, 2014 Oct 02, 2014

Copy link to clipboard

Copied

And if you're talking Javascript, you have the LayerSet.visible for that. Just remember you have multiple ways of going through a document

  • ArtLayer is the thing called "layer" in Photoshop, i.e. ~content
  • LayerSet is a group in Photoshop
  • Layer is either, you'll know by Layer.typename
  • .artLayers and .layerSets are collections of just those and .layers is a collection of either.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 02, 2014 Oct 02, 2014

Copy link to clipboard

Copied

Thanks for the clarification. I looked up the layer groups in the object document model and found the terminology for a layer group confusing.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 02, 2014 Oct 02, 2014

Copy link to clipboard

Copied

I have a script that does what you need. Can't remember if I obtained it from here, but I do know that the scripting guys in here are geniuses and can help you out with almost anything. That said, here is the script that you need. All you need to do is replace the three "Insert Layer Name Here" portions with the name of the layer you wish to toggle on/off. Don't thank me, thank whoever wrote it, (most likely someone here)

var targetID = getLayerIDByName('Insert Layer Name here');

if(undefined != targetID){

    if(getLayerVisibilityByID( targetID ) ){

        hideByName('Insert Layer Name here');

    }else{

        showByName('Insert Layer Name here');

    }

}

function getLayerIDByName(name) {

    try{

    var ref = new ActionReference();

    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "LyrI" ));

    ref.putName( charIDToTypeID( "Lyr " ), name );

    return executeActionGet(ref).getInteger(charIDToTypeID( "LyrI" ));

    }catch(e){}

};

function getLayerVisibilityByID( id ) {

    var ref = new ActionReference();

    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Vsbl" ));

    ref.putIdentifier( charIDToTypeID( "Lyr " ), id );

    return executeActionGet(ref).getBoolean(charIDToTypeID( "Vsbl" ));

};

function hideByName(name) {

    var desc = new ActionDescriptor();

        var list = new ActionList();

            var ref = new ActionReference();

            ref.putName( charIDToTypeID('Lyr '), name );

        list.putReference( ref );

    desc.putList( charIDToTypeID('null'), list );

    executeAction( charIDToTypeID('Hd  '), desc, DialogModes.NO );

};

function showByName(name) {

    var desc = new ActionDescriptor();

        var list = new ActionList();

            var ref = new ActionReference();

            ref.putName( charIDToTypeID('Lyr '), name );

        list.putReference( ref );

    desc.putList( charIDToTypeID('null'), list );

    executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );

};

EDIT- whoops, I just realized this is only for layers, not groups. But hopefully it's a starting point

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 02, 2014 Oct 02, 2014

Copy link to clipboard

Copied

No worries, I realize it was for layer when I skimmed the script. Strangely enough it works  with layer groups also.

Thanks!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 14, 2018 Feb 14, 2018

Copy link to clipboard

Copied

This script is works perfect but toggles only the first layer with specific name. Is there any possibility to toggle ALL the layers with this specific name?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2018 Feb 14, 2018

Copy link to clipboard

Copied

LATEST

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines