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

activeLayer returns a layer when no layer is selected

Explorer ,
Sep 28, 2018 Sep 28, 2018

Hello,

I'm having a problem with activeLayer, even when i have no layer selected in photoshop it returns my most recently selected layer, how do i know if the user has selected a layer or not?

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

People's Champ , Sep 28, 2018 Sep 28, 2018

In CC2018 you can use

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));

r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

if (!executeActionGet(r).hasKey(stringIDToTypeID("targetLayers"))) alert("No Layer selected")

Translate
Adobe
Advocate ,
Sep 28, 2018 Sep 28, 2018

I hope I understand correctly

this script enables last level at the top.

var newLayer = app.activeDocument.artLayers.add(); 

newLayer.remove();

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
Explorer ,
Sep 28, 2018 Sep 28, 2018

No that was not quite what i was looking for.

The issue i'm having is that i want to know if the user has selected a layer or not, but activeLayer always returns a layer even if the user has no layer selected.

How do i know if the user has no layer selected?

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
People's Champ ,
Sep 28, 2018 Sep 28, 2018

In CC2018 you can use

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));

r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

if (!executeActionGet(r).hasKey(stringIDToTypeID("targetLayers"))) alert("No Layer selected")

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
Explorer ,
Sep 28, 2018 Sep 28, 2018

Thanks, that did show me if the user had any layers selected or not.

Would this be possible in DOM code aswell?

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
People's Champ ,
Sep 28, 2018 Sep 28, 2018

I think NO.

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
People's Champ ,
Sep 28, 2018 Sep 28, 2018
LATEST

By the way, to activate the activeLayer, you can use

try { activeDocument.activeLayer.link(activeDocument.activeLayer) } catch(e) { /*happens when the background is a single layer*/ }

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