Copy link to clipboard
Copied
Hello everyone,
I have a document with an empty layer and I made a selection. When I click Ctrl+C to copy i get this "Could not complete the Copy command because the selected area is empty." any idea on how to throw a try catch or if in a script? (if I can't copy I want an alert "can't copy")
This?
try { executeAction(stringIDToTypeID("copyEvent"), undefined, DialogModes.NO); } catch(e) { alert("can't copy!"); }
Copy link to clipboard
Copied
This?
try { executeAction(stringIDToTypeID("copyEvent"), undefined, DialogModes.NO); } catch(e) { alert("can't copy!"); }
Copy link to clipboard
Copied
Yes:)
can I leave catch(e) empty if I have nothing to put there?
to be more clear, i have a selection which I don't know if it has active pixels in it.
I want to copy it (if I can)(using try and catch), and then i need to paste it to a new layer, for example:
app.activeDocument.artLayers.add();
app.activeDocument.selection.deselect();
app.activeDocument.paste();
or something like that
Copy link to clipboard
Copied
if (copy())
{
app.activeDocument.artLayers.add();
app.activeDocument.selection.deselect();
paste();
}
else alert("WTF!");
function copy()
{
try { executeAction(stringIDToTypeID("copyEvent"), undefined, DialogModes.NO); } catch(e) { return false; }
return true;
}
function paste()
{
try { executeAction(stringIDToTypeID("paste"), undefined, DialogModes.NO); } catch(e) { return false; }
return true;
}
Copy link to clipboard
Copied
absolutely great!
Aren't copy and paste reserved words though? (how can we use them as a function name)
Copy link to clipboard
Copied
What do you want to ask?
If anything, these are not reserved words.
Copy link to clipboard
Copied
thank you r-bin.
if i have an active selection ('try' worked), when i copy and then paste, the selection is pasted in a different location unlike Layer Via Copy that keeps the selection in the same location. i'll add 2 images so it will be more clear. i marked in red the small selection that is active and the bigger selection that isn't active.
is this possible to keep it in the same location?
BEFORE
AFTER (i used the script from before to copy and paste)
Copy link to clipboard
Copied
i believe i got a solution myself, I duplicated the layer and then inverse>delete. The remaining is in the same location without the need to copy and paste.