Check selection of layers
How do I check if I have two layers selected?
If you only have one or baby, trigger an alert message: "You need to select two layers!"
Thanks for the support
How do I check if I have two layers selected?
If you only have one or baby, trigger an alert message: "You need to select two layers!"
Thanks for the support
r-bin escreveu
Do you just need to know if two layers are selected or do you need to get two objects of type Layer (ArtLayer) or is there enough only layers IDs?
I just need to know if two layers are selected, if true, a scpit will be executed, if not; that there is an alert message and do nothing.
alert(ckeck_2_selected())
function ckeck_2_selected()
{
try {
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r);
if (!d.hasKey(stringIDToTypeID("targetLayers"))) return false;
var l = d.getList(stringIDToTypeID("targetLayers"));
if (l.count != 2) return false;
var n = 0;
try { activeDocument.backgroundLayer } catch (e) { n = 1; }
for (var i = 0; i < 2; i++)
{
var r = new ActionReference();
r.putIndex(stringIDToTypeID("layer"), l.getReference(i).getIndex() + n);
if (executeActionGet(r).getEnumerationValue(stringIDToTypeID("layerSection")) != stringIDToTypeID("layerSectionContent")) return false;
}
return true;
}
catch(e) { alert(e); throw e; }
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.