Copy link to clipboard
Copied
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?
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")
Copy link to clipboard
Copied
I hope I understand correctly
this script enables last level at the top.
var newLayer = app.activeDocument.artLayers.add();
newLayer.remove();
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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")
Copy link to clipboard
Copied
Thanks, that did show me if the user had any layers selected or not.
Would this be possible in DOM code aswell?
Copy link to clipboard
Copied
I think NO.
Copy link to clipboard
Copied
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*/ }
Find more inspiration, events, and resources on the new Adobe Community
Explore Now