Skip to main content
Known Participant
October 9, 2010
Answered

Hide All Layers

  • October 9, 2010
  • 2 replies
  • 1410 views

I have over 150 different designs used in events as Backgrounds. Some have one selection others up to six. Using Event Manager invoking an action which Past into the different selection I find myselfe always clicking Stop several times when using fewer than 6 selections. Yes I could Delete or Hide the Layers in the action because I always close when finished with an action "Close No Save" but I think a script would do better. The script should hide all layers regardless how many there are. My backgrounds have no other Layers called Layers but only the ones pasted will be named Layer 1, Layer 2 etc.

Here is a sample of what I do: Could someone help me out please.

http://www.pixentral.com/show.php?picture=1lYFhA8misPZcBJm5mQwdbfIk3jPY1

This topic has been closed for replies.
Correct answer c.pfaffenbichler

I did not include a number-check but only identified them by their names starting with »Layer «, still you could give this a try:

// 2010, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

  hideLayers(app.activeDocument);

  };

////// function to hide all pixel-layers //////

function hideLayers (theParent) {

if (!allLayers) {var allLayers = new Array}

else {};

for (var m = theParent.layers.length - 1; m >= 0;m--) {

var theLayer = theParent.layers;

// apply the function to layersets;

    if (theLayer.typename == "ArtLayer") {

      if (theLayer.name.slice(0, 6) == "Layer ") {

        theLayer.visible = false;

        };

      allLayers.push(theLayer)

      }

    else {

      allLayers = allLayers.concat(hideLayers(theLayer))

      }

    };

  return allLayers

  };

2 replies

JJMack
Community Expert
Community Expert
October 9, 2010
Norman_BeAuthor
Known Participant
October 9, 2010

Thanks for the link but I made a mistake in the questio

n it should read: Hide All Numbered Layers. P

lease see here..

http://www.pixentral.com/show.php?picture=15Udi9sGUfXvGQYBBO0ANjAb278EG

c.pfaffenbichler
Community Expert
Community Expert
October 9, 2010

I do not follow your description and the link does not seem to work.

Could you explain a bit more detailed what the Action is supposed to achieve?

Still if you just want to hide all layers something like this might suffice:

// 2010, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

  hideLayers(app.activeDocument);

  };

////// function to hide all pixel-layers //////

function hideLayers (theParent) {

if (!allLayers) {var allLayers = new Array}

else {};

for (var m = theParent.layers.length - 1; m >= 0;m--) {

var theLayer = theParent.layers;

// apply the function to layersets;

    if (theLayer.typename == "ArtLayer") {

        theLayer.visible = false;

        allLayers.push(theLayer)

        }

    else {

      allLayers = allLayers.concat(hideLayers(theLayer))

      }

    };

  return allLayers

  };

Norman_BeAuthor
Known Participant
October 9, 2010

Thanks for the help but I made a mistake in the Topic it should read:  Hide All Numbered Layers.

Please see here:

http://www.pixentral.com/show.php?picture=15Udi9sGUfXvGQYBBO0ANjAb278EG

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
October 9, 2010

I did not include a number-check but only identified them by their names starting with »Layer «, still you could give this a try:

// 2010, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

  hideLayers(app.activeDocument);

  };

////// function to hide all pixel-layers //////

function hideLayers (theParent) {

if (!allLayers) {var allLayers = new Array}

else {};

for (var m = theParent.layers.length - 1; m >= 0;m--) {

var theLayer = theParent.layers;

// apply the function to layersets;

    if (theLayer.typename == "ArtLayer") {

      if (theLayer.name.slice(0, 6) == "Layer ") {

        theLayer.visible = false;

        };

      allLayers.push(theLayer)

      }

    else {

      allLayers = allLayers.concat(hideLayers(theLayer))

      }

    };

  return allLayers

  };