Answered
Script: Delete selected layer, if empty.
There are various ways to delete all layers that are empty, but is there a script which can detect if the "selected" layer is empty, and if so, delete it?
Thanks!
Jeff
There are various ways to delete all layers that are empty, but is there a script which can detect if the "selected" layer is empty, and if so, delete it?
Thanks!
Jeff
I'm using CS6.. lol
Thanks!
Option for CS6
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var list = executeActionGet(r).getList(stringIDToTypeID("targetLayers"));
var selected = new Array();
var ids = new Array();
for (var i = 0; i < list.count; i++) selected.push(list.getReference(i).getIndex());
for (var i = 0; i < selected.length; i++)
{
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIndex(stringIDToTypeID("layer"), selected[i]);
var bounds = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));
var x0 = bounds.getUnitDoubleValue(stringIDToTypeID("left"));
var x1 = bounds.getUnitDoubleValue(stringIDToTypeID("right"));
var y0 = bounds.getUnitDoubleValue(stringIDToTypeID("top"));
var y1 = bounds.getUnitDoubleValue(stringIDToTypeID("bottom"));
if (!x0 && !x1 && !y0 && !y1) ids.push(selected[i]);
}
if (ids.length)
{
var r = new ActionReference();
for (var i = 0; i < ids.length; i++) r.putIndex(stringIDToTypeID("layer"), ids[i]);
var d = new ActionDescriptor();
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.