Last active
July 19, 2023 14:44
-
-
Save edygar/1ac6c72931b6dd800271 to your computer and use it in GitHub Desktop.
Illustrator Script: Convert Groups under selected to Layers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
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
Awesome script, thank you!