Select layer by index doesn't work correctly when a background layer is in your document.
I came across a strange "bug" when incorrect layers were selected using select by ID methode.
The following code should simply alert the currently selected layer and index of it, than using the select by index function, select that same layer, and than reports back the selected layers index. Both should be the same if it's working correctly, and in some psd's its working perfect, select a layer with index 10, and after selecting, layer index 10 is still selected. But some psd's were not working correctly. And I discovered that when a background layer is present, the select by ID isn't working correctly anymore, you select 10, and than it selects 11 instead.
Here is the test code I used...
sTT = stringIDToTypeID;
function actionManagerSelectLayerByIndex(itemIndex, makeVisible){
var d1 = new ActionDescriptor();
var r1 = new ActionReference();
r1.putIndex( sTT('layer'), itemIndex );
d1.putReference( sTT('null'), r1 );
d1.putBoolean( sTT('MkVs'), makeVisible );
executeAction( sTT('select'), d1, DialogModes.NO );
}
alert("Selected Layer: " + activeDocument.activeLayer + " - ItemIndex: " + activeDocument.activeLayer.itemIndex)
actionManagerSelectLayerByIndex(activeDocument.activeLayer.itemIndex, true);
alert("Selected Layer: " + activeDocument.activeLayer + " - ItemIndex: " + activeDocument.activeLayer.itemIndex)
I want to use the function select by index to select the layer above or below the currently selected layer. But that just became unreliable... Is anyone aware of this issue?
