I have a script that searches for slices using save to web trick and then does a selection then tries to copy doing the following:
app.activeDocument.selection.select(selectRect);
if (activeDocument.selection != null)
{
app.activeDocument.selection.copy();
app.activeDocument.paste();
app.activeDocument.activeLayer.name = layerName;
}
However if my the selection has no pixels I get an error in the console: "
General Photoshop error occurred.\n- Could not complete the command because the selected area is empty."
I have tried to wrap the code in a try-catch but doesnt seem to help..
Checking for empty area before copy?
Checking for empty area before copy?
activeDocument.selection will always return the object [selection] so your if test will alway test true. The selection object is broken in PS7, CS, and CS2 otherwise you could test selection.bounds to see if the selection is empty.
But I find a try/catch block works for me with either empty or no selection
Code: Select all try{
app.activeDocument.selection.copy();
alert('selection copied');
}catch(e){
alert('error')
};;
If that doesn't work for you and you are running the script in ESTK check to see that 'Don't break on guarded exceptions' is checked under the debug menu
But I find a try/catch block works for me with either empty or no selection
Code: Select all try{
app.activeDocument.selection.copy();
alert('selection copied');
}catch(e){
alert('error')
};;
If that doesn't work for you and you are running the script in ESTK check to see that 'Don't break on guarded exceptions' is checked under the debug menu