Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Due to my non-US keyboard I've had to make an Action that maps "Select forward layer" to an F-key.

However the "Select forward layer" doesn't select invisible layers.

Is there a way to select the forward layer, despite it being invisible?

share|improve this question

migrated from photo.stackexchange.com Mar 10 '11 at 0:08

This question came from our site for professional, enthusiast and amateur photographers.

    
This is really a computer user help question, rather than a photography question. I'm moving to SuperUser.com, where you should get better help. –  jrista Mar 10 '11 at 0:07
add comment

3 Answers 3

Assuming that by forward layer you mean top layer, you can do this with a simple script. Open your ExtendScript Toolkit (it should have installed along with Photoshop) and make a new Javascript document. Then enter:

var doc = app.activeDocument; //references current document
doc.activeLayer = doc.layers[0]; //selects the top layer

This will make the top layer visible when it's selected. If you want to keep it invisible, add the following line at the end:

doc.activeLayer.visible = false;

Save it in your Presets/Scripts folder for convenience (though it can go anywhere).

Then go into Photoshop, make a new file, start recording a new Action, then go to File > Scripts > Browse, and find your script. Opening it runs it. Once it's run, stop recording and just assign a shortcut key to the action, et voila!

If for any reason you can't find the ExtendScript Toolkit, just put the code in a blank text document and change the extension to .jsx . If you move the script file after you've recorded the action you will have to re-record it as it remembers the path.

share|improve this answer
    
By "forward" I mean "next" layer - is there a way to script selecting the "next" or "previous" layer? Photoshop's built in action allows you to select next and previous layers, however it ignores invisible layers. I don't want to change the visibility of the layer, I just want to be able to select them regardless of visibility. –  timkl Mar 10 '11 at 11:24
add comment

I managed to do this by slightly modifying the script I found on AHK forum (that one switched target layer forcefully to visible and had other minor errors), and it's works for me:

var doc = app.activeDocument;
var currentLayer = doc.activeLayer;


for(i=0; i < doc.layers.length; )
{         
  if(doc.layers[i]==currentLayer)
  {
      a=i;
      //alert(a);
      i = doc.layers.length;
  }
  else{ i++; }
}


try
{
  var nextLayer = doc.layers[a+1];
  var check = nextLayer.visible;
}
catch(e)
{
  var nextLayer = doc.layers[0];
  var check = nextLayer.visible;
}  

doc.activeLayer = nextLayer;
if (check == false)
  doc.activeLayer.visible = false;

This is for stepping to the next (down) layer; for previous (up) just make another script with changes [a+1] to [a-1] in TRY section and [0] to [doc.layers.length-1] in CATCH section. Well, in the following, the common way: place both scripts in Ps script folder, make Action with "Insert Menu Item" and assign hotkeys as you wish. You may later use even your fav AHK shortcuts and so on...

share|improve this answer
add comment

A little addition to the scripts above.

After testing those in Ps I've stumbled upon the fact that if there are groups in the current workflow, scripts don't work properly. They don't take in account layers inside groups, known as layerSets in script language; when the script lists through "layers" it handles only upper level elements (layers outside groups and groups themselves).

So I took a try to adjust them to more extended needs.

Modified scripts are below; they can handle properly workflows with upper level layers&groups and nested elements in upper level groups. With more hierarchy they will work too, if active layer is not twice nested element (otherwise "down"-script will switch to uppermost layer and "up"-script will simply do nothing). But I really very rarely deal with more than once nested groups and at the worst one can do good old mouse click if too necessary (ore use legacy Alt+[/] shortcuts, they still work on all non-hidden layers howsoever nested).

Sorry, I'm not a programmer by far, so full-functional code is beyond my brains; furthermore, these scripts are quite bulky too, I suppose. But they work. (For example, I assign "up"-cycle to F3, "down"-cycle to F4 and "toggle-visibility"-script to F2; for me this combination is quite handy and saves much time).

"Cycle-down"-script

var doc = app.activeDocument;
var currentLayer = doc.activeLayer;
//===========
var gropp = doc.layerSets.length;
var docl = doc.layers.length;
var sublayer = 0;
//alert(gropp)
for (i=0; i < gropp;)
{
sublayer = sublayer + doc.layerSets[i].layers.length;
i++;
}
//==============
var a = -1
var kk = -1
var aa = -1
//если активный слой - элемент высшего порядка:
for(i=0; i<docl;)
{
  if(doc.layers[i]==currentLayer)
  {
     a=i;
     i = docl;
  }
  else{ i++;}
}
//если активный слой - элемент группы:
if (a<0)
{
  for (i=0; i<gropp;)
  {
     var subdocl = doc.layerSets[i].layers.length;
     for (k=0; k<subdocl;)
     {
       if(doc.layerSets[i].layers[k]==currentLayer)
       {
          aa = i;
          kk = k;
          k = doc.layerSets[i].layers.length;
          i = gropp-1;
       }
       else { k++; }
      }
     i++;
  }
}
//ACTIVATING
//если активный слой - слой высшего порядка:
if (kk<0)
{
    //если активный слой - группа (т.е. нижележ. слой - внутри её):
    for (i=0; i<gropp;)
    {
        if (doc.layerSets[i] == currentLayer)
        {
            var nLayer = doc.layerSets[i].layers[0];
            var check = nLayer.visible;
            doc.activeLayer = nLayer;
            var isGroup = true;
            var isActived = true;
            if (check == false)
            doc.activeLayer.visible = false;
            i = gropp;
        }
        else {i++;}
    }
    //если активный слой - простой слой (будет обрабатываться в try-catch):
    if (isGroup != true)
    {
        for (i=0; i<docl;)
        {
            if (doc.layers[i]==currentLayer)
            {
                numm = i;
                i=docl;
            }
            else {i++;}
        }
    }
}
else
//(если активный слой - подобъект (элемент группы), т.е. известны (неотриц.) aa и kk:
{
    //если элемент группы - последний в ней (будет обрабатываться в try-catch):
    if (kk == subdocl-1)
    {
        for (i=0; i<docl;)
        {
            if (doc.layers[i] == doc.layerSets[aa])
            {
                numm = i;
                i = docl;
            }
            else {i++;}
        }
    }
    //если не последний в группе, то проще:
    else
    {
        var nLayer = doc.layerSets[aa].layers[kk+1];
        var check = nLayer.visible;
        doc.activeLayer = nLayer;
        var isActived = true;
        if (check == false)
        doc.activeLayer.visible = false;
    }
}

//try-catch секция для последних вариантов (самых нижних слоёв):
try
{
    //alert ("isActived is " + isActived)
    if (isActived != true)
    {
        var nLayer = doc.layers[numm+1];
        var check = nLayer.visible;
        doc.activeLayer = nLayer;
        if (check == false)
        doc.activeLayer.visible = false;
    }
}
catch(e)
{
  var nLayer = doc.layers[0];
  var check = nLayer.visible;
  doc.activeLayer = nLayer;
  if (check == false)
  doc.activeLayer.visible = false;
} 

"Cycle-up" script

var doc = app.activeDocument;
var currentLayer = doc.activeLayer;

var gropp = doc.layerSets.length;
var docl = doc.layers.length;

var a = -1
var kk = -1
var aa = -1

//если активный слой - элемент высшего порядка:
for(i=0; i<docl;)
{
  if(doc.layers[i]==currentLayer)
  {
     a=i;
     i = docl;
  }
  else{ i++;}
}

//если активный слой - элемент группы:
if (a<0)
{
  for (i=0; i<gropp;)
  {
     var subdocl = doc.layerSets[i].layers.length;
     for (k=0; k<subdocl;)
     {
       if(doc.layerSets[i].layers[k]==currentLayer)
       {
          aa = i;
          kk = k;
          k = doc.layerSets[i].layers.length;
          //модернизируем скрипт: вносим сразу в этот цикл обработку активизации.
            //если элемент группы - первый в ней (активизируем саму группу - гипероним):
          if (kk==0)
          {
              var pLayer = doc.layerSets[i];
              var check = pLayer.visible;
              doc.activeLayer = pLayer;
              //var isGroup = true;
              var isActived = true;
              if (check == false)
              doc.activeLayer.visible = false;
          }
            //если не первый, то просто слой вверх:
          else
          {
              var pLayer = doc.layerSets[i].layers[kk-1];
              var check = pLayer.visible;
              doc.activeLayer = pLayer;
              var isActived = true;
              if (check == false)
              doc.activeLayer.visible = false;
          }
          i = gropp-1;
       }
       else { k++; }
     }
     i++;
  }
}
//если активный слой - высший элемент; нам известно (неотриц) a:
else
{
    if (a==0)
    a=docl;
    for (i=0; i<gropp;)
    {
        //если предыдущий слой - последний элемент находящейся выше группы:
        if (doc.layerSets[i] == doc.layers[a-1])
        {
            var subdocl = doc.layerSets[i].layers.length;
            var pLayer = doc.layerSets[i].layers[subdocl-1];
            var check = pLayer.visible;
            doc.activeLayer = pLayer;
            var isActived = true;
            if (check == false)
            doc.activeLayer.visible = false;
            i = gropp;
        }
        else {i++;}
    }
    if (isActived != true)
    {
        var pLayer = doc.layers[a-1];
        var check = pLayer.visible;
        doc.activeLayer = pLayer;
        if (check == false)
        doc.activeLayer.visible = false;
    }
}

"Bonus" - "toggle visibility"-script

var currentLayer = activeDocument.activeLayer;
currentLayer.visible = !currentLayer.visible

Note: Save them as *.jsx files and put in C:\Program Files\Adobe\%Your Adobe Version Folder%\Presets\Scripts

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.