Copy link to clipboard
Copied
I create a script which cycles through all my layer comps, resize them and save to various folders.
one of the command i use is:
activeDocument.mergeVisibleLayers();
I finally figured out that i would get this error message:
Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- The command "Merge Visible" is not currently available
when i am running the script when a non visible layer is currently selected.
This can happen when a new layer comp is selected where the active layer should be turned off.
Is there an elegant way to force a selection of a visible layer when the script runs to avoid such errors?
Thanks
I ended up selecting the top most visible layer like shown below:
function SelectTopVisibleLayer() {
for (var i = 0; i < activeDocument.layers.length; i++){
var theLayer = activeDocument.layers;
if (theLayer.typename === "ArtLayer" ){
//select a visible layer - any layer
if(theLayer.visible == true){
activeDocument.activeLayer =activeDocument.layers.getByName(theLayer.name);
break;
}
}
}
}
Copy link to clipboard
Copied
May be suitable
app.activeDocument.flatten();
or
app.activeDocument.artLayers.add();
app.activeDocument.mergeVisibleLayers();
Copy link to clipboard
Copied
I ended up selecting the top most visible layer like shown below:
function SelectTopVisibleLayer() {
for (var i = 0; i < activeDocument.layers.length; i++){
var theLayer = activeDocument.layers;
if (theLayer.typename === "ArtLayer" ){
//select a visible layer - any layer
if(theLayer.visible == true){
activeDocument.activeLayer =activeDocument.layers.getByName(theLayer.name);
break;
}
}
}
}