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

empty selection

New Here ,
Mar 29, 2016 Mar 29, 2016

Hi everyone,

How to test if a selection is empty?

If I try to access the bounds, the object does not exist, if I test the selection object it seems fine.

Thanks

Christian

TOPICS
Actions and scripting
1.7K
Translate
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

Community Expert , Mar 30, 2016 Mar 30, 2016

There may not be a way to do this without the try/catch block.

Translate
Adobe
Community Expert ,
Mar 29, 2016 Mar 29, 2016

You can use a try/catch block with copy to see if it errors"

#target photoshop

var doc = activeDocument;

try{

     doc.selection.copy()

     //code here if there is something in the selection

     }

catch(e){

     //code here for if the selection is empty

     }

Translate
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
New Here ,
Mar 29, 2016 Mar 29, 2016

Thank you, but I would have liked a test without the try/catch, which works, I confirm.

cb

Translate
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
Community Expert ,
Mar 30, 2016 Mar 30, 2016

There may not be a way to do this without the try/catch block.

Translate
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
Guide ,
Mar 30, 2016 Mar 30, 2016

This function is from xbytor.

function hasSelection (doc) {

if(doc == undefined) doc = activeDocument;

  var res = false;

  var as = doc.activeHistoryState;

  doc.selection.deselect();

  if (as != doc.activeHistoryState) {

    res = true;

    doc.activeHistoryState = as;

  }

  return res;

};

Translate
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
Community Expert ,
Mar 30, 2016 Mar 30, 2016
LATEST

If the object that may or may not exists it one its own layer you could test that layer bounds to see if it empty,  I wrote script and tested the layers boundry of an empty layer not a selection  bounds for a selection on an enpty will have a bounds but the lauyer's bound seems to be all zeros.

Capture.jpg

JJMack
Translate
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