Skip to content

Instantly share code, notes, and snippets.

@edygar
Last active July 19, 2023 14:44
Show Gist options
  • Save edygar/1ac6c72931b6dd800271 to your computer and use it in GitHub Desktop.
Save edygar/1ac6c72931b6dd800271 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);
@dzg
Copy link

dzg commented May 5, 2020

This is fantastic, thank you!

@N8Dean
Copy link

N8Dean commented Sep 1, 2020

So useful! Especially for After Effects users. THANK YOU SO MUCH

@Toliak
Copy link

Toliak commented Apr 8, 2021

Awesome script, thank you!

@designnewb
Copy link

Is there a way to make them not sublayers but actually into seperate layers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment