I wrote a script to apply a high-pass filter to every layer at the root layer hierarchy:
Code: Select all
function applyHighPassFilterAllLayers(radius) {
var doc = activeDocument;
var layers = activeDocument.layers;
for (var layerIndex=0; layerIndex < layers.length; layerIndex++) {
var layer = layers[layerIndex];
doc.activeLayer = layer;
layer.applyHighPass(radius);
}
}
The above script works if any layer is active in the UI prior to running the script (ie, a single layer is highlighted/selected in the layers panel). However, if no layer is active in the UI then the script fails with PS reporting "The command High Pass it not currently available". This seems to occur because PS doesn't think any layer is active even though my code is setting the active layer inside the loop. If I examine activeDocument.activeLayer prior to entering my loop I see it the first layer is the active layer even though it's not visibly active in the UI, yet it still fails. With trial and error I can get the script to work in this scenario if I set a different layer as active prior to the loop. For example:
Code: Select all
function applyHighPassFilterAllLayers(radius) {
var doc = activeDocument;
var layers = activeDocument.layers;
doc.activeLayer = layers[1]; // temporary workaround - set second layer as active prior to entering layer loop below
for (var layerIndex=0; layerIndex < layers.length; layerIndex++) {
var layer = layers[layerIndex];
doc.activeLayer = layer;
layer.applyHighPass(radius);
}
}
Any ideas on how I can get this to work without the temporary workaround I put in?