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

Select 2 layers

Enthusiast ,
Oct 13, 2013 Oct 13, 2013

does anyone know if there's a way to keep the active layer selected, and also select the layer above it? In other words there would be 2 selected layers: the active layer, and the layer directly above it (regardless of its name)

It can be done easily by holdinmg down the shift key and just clicking on the layer above the active one in the layers panel, but I'm not quite sure that it could be done via scripting? Thanks in advance..

TOPICS
Actions and scripting
1.4K
Translate
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
Adobe
Enthusiast ,
Oct 14, 2013 Oct 14, 2013

update- I found the keyboard shortcut (had to research the forums a bit). The keyboard shortcut to keep the active layer selected and as well select the layer above it is ALT+SHIFT+]

the problem is that this shortcut ignores invisible layers (layers with their visibility turned off).. it selects the next layer above that has its visibility set to on... so if the layer above is turned off, it ignores it and jumps up to the next 'visible' layer..is there a way to select a layer even if it has its visibility off?

Translate
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
Guru ,
Oct 14, 2013 Oct 14, 2013

This should work. You can give it a better name if you like.

function getLayerLayerSectionByIndex( index ) {            
     var ref = new ActionReference(); 
     ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID("layerSection")); 
     ref.putIndex(charIDToTypeID("Lyr "), index);
     return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID("layerSection")));
}; 
function someFunctionName() {
    if(activeDocument.activeLayer==activeDocument.layers[0]) return;// if top layer do nothing
    var ref = new ActionReference();// get am index of activeLayer
    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var index = executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))+Number(activeDocument.layers[activeDocument.layers.length-1].isBackgroundLayer);
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putIndex( charIDToTypeID('Lyr '), getLayerLayerSectionByIndex( index+1 ) == 'layerSectionEnd' ? index+2:index+1 );// make sure next layer is valid( not invisible layerSet end )
    desc.putReference( charIDToTypeID('null'), ref );
    desc.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection') );
    desc.putBoolean( charIDToTypeID('MkVs'), false );
    executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
}
someFunctionName()
Translate
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
Community Expert ,
Oct 14, 2013 Oct 14, 2013

Is it possible the Script overlooks the parental Group if the active Layer is a Group and topmost within a Group?

Translate
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
Guru ,
Oct 14, 2013 Oct 14, 2013

I threw that together quickly without much testing. It is possible there are several case where it will fail.

Translate
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 14, 2013 Oct 14, 2013

so close... it's keeping the active layer selected, then it also selects the layer 3 levels up (for example, the active layer is selected, then the 2 layers above it are left alone, but the next one above those two becomes selected as well)

it all leads me back to a similar problem I was having a while ago, which was that the keyboard shortcut to select up or down one layer is ALT+[ (select next layer down) or ALT+] (select next layer up), but it ignored invisible layers, and I was never able to figure out a way to solve it- just want to select layer up or layer down, regardless of its visibility

Translate
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
Guru ,
Oct 14, 2013 Oct 14, 2013

oops, change this line

var index = executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-Number(activeDocument.layers[activeDocument.layers.length-1].isBackgroundLayer);

This should do what you want now. The only way I know to add the layer above the active layer is to get the active layer's am index and use that to select the layer above. It doesn't help that the am index has no relation to the DOM layer index, changes depending on if there is a background layer in the document, and that there is an index for the bottom of a layerSet.

Translate
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 14, 2013 Oct 14, 2013

It works now Michael, thanks! Can I ask one more thing - how would you select the next layer above (or down for that matter), regardless of its visibility? It would be the same as ALT+[ or ALT+], but it would also select invisible layers, too... 

Translate
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
Guru ,
Oct 14, 2013 Oct 14, 2013

The code I posted adds the layer above to the selected layers. To just select the layer above comment out the line

desc.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection') );

To select the layer below change this line

ref.putIndex( charIDToTypeID('Lyr '), getLayerLayerSectionByIndex( index-1 ) == 'layerSectionEnd' ? index-2:index-1 )

And you should add a test to check if you are already on the bottom layer.

Translate
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 14, 2013 Oct 14, 2013
LATEST

Thanks Mike- I adjusted the script and it works - finally, a solution to a problem I've been scoping out for many months now

Translate
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