Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dzg/c66b66afd28577780c772f27e893d6f7 to your computer and use it in GitHub Desktop.
Save dzg/c66b66afd28577780c772f27e893d6f7 to your computer and use it in GitHub Desktop.
Illustrator Script: Convert Groups under selected to Layers
// Save to... /Applications/Adobe Illustrator CC/Presets.localized/<LOCALE>/Scripts/
// Polyfill for forEach
function forEach(array, fn, scope) {
scope = scope || array;
// array is cloned in order to allow mutations
// in `fn` but not suffer from them, so iteration
// keeps normally.
array = Array.prototype.slice.call(array,0);
for(var i = 0, len = array.length; i < len; i++) {
fn.call(scope, array[i], i, array);
}
}
function convertGroupToLayer(item) {
var newLayer = app.activeDocument.layers.add(); // creates a new layer
newLayer.name = item.name; // rename layer same as group
forEach(item.pageItems, function(el) {
el.move(newLayer,ElementPlacement.PLACEATEND); // move group to new layer
});
newLayer.move(item, ElementPlacement.PLACEBEFORE);
item.remove();
}
// forEach pageItem of activeLayer, convertGroupToLayer
forEach(app.activeDocument.activeLayer.groupItems, convertGroupToLayer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment