Mysterious behavior, layer becomes visible, why?
I encountered strange behavior of a complex function where the originally active layer becomes visible for no reason. After allot of testing, I isolated the issue, and I still have no clue why it is happening.
The following script demonstrates the issue.
When you have a document with 10 layers, you make layer 8 invisible, and select layer 8 when running this script, this script simply saves the initially active layer 8 to a variable first, than selects layer 4 using action manager code (select layer by ID), and then restores the originally active layer 8. And for some reason, making the original layer 8 active again, it also making it visible. And this only happens in this combination, selecting by id using action manager code and than selecting it using the API.
Anyone any ideas on whats happening here?
function actionManagerSelectLayerById(layer, makeVisible){
var d1 = new ActionDescriptor();
var r1 = new ActionReference();
r1.putIdentifier(app.charIDToTypeID('Lyr '), layer.id);
d1.putReference(app.charIDToTypeID('null'), r1);
d1.putBoolean(app.charIDToTypeID('MkVs'), makeVisible);
executeAction(app.charIDToTypeID('slct'), d1, DialogModes.NO);
}
var initialLayer = app.activeDocument.activeLayer
actionManagerSelectLayerById(app.activeDocument.layers[3], false)
app.activeDocument.activeLayer = initialLayer;
Update...
I noticed just now it's because making a layer active using the API is simply making it visible. I guess this is default behaviour that I didn't realise. This post can be deleted
