8 Replies Latest reply on Feb 14, 2018 7:32 PM by Kukurykus

    layer group visibility toggle

    ojodegato Level 1

      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.

        • 1. Re: layer group visibility toggle
          c.pfaffenbichler Level 9

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

          • 2. Re: layer group visibility toggle
            matias.kiviniemi Level 3

            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.
            • 3. Re: layer group visibility toggle
              boo radley 2013 Level 3
              
              
              
              

              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

              • 4. Re: layer group visibility toggle
                ojodegato Level 1

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

                Thanks!

                • 5. Re: layer group visibility toggle
                  ojodegato Level 1

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

                  • 6. Re: layer group visibility toggle
                    ojodegato Level 1

                    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.

                    • 7. Re: layer group visibility toggle
                      usx40303570 Level 1

                      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?