• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Try to copy when no pixels where selected

Engaged ,
Mar 09, 2019 Mar 09, 2019

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")

TOPICS
Actions and scripting

Views

2.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Mar 09, 2019 Mar 09, 2019

This?

try { executeAction(stringIDToTypeID("copyEvent"), undefined, DialogModes.NO); } catch(e) { alert("can't copy!"); }

Votes

Translate

Translate
Adobe
People's Champ ,
Mar 09, 2019 Mar 09, 2019

Copy link to clipboard

Copied

This?

try { executeAction(stringIDToTypeID("copyEvent"), undefined, DialogModes.NO); } catch(e) { alert("can't copy!"); }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 09, 2019 Mar 09, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 09, 2019 Mar 09, 2019

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;

    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 10, 2019 Mar 10, 2019

Copy link to clipboard

Copied

absolutely great!

Aren't copy and paste reserved words though? (how can we use them as a function name)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 10, 2019 Mar 10, 2019

Copy link to clipboard

Copied

What do you want to ask?

If anything, these are not reserved words.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 10, 2019 Mar 10, 2019

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 10, 2019 Mar 10, 2019

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines