Created
October 15, 2021 14:31
-
-
Save hjhilden/974f1de7df6317451f9d365265ffd05c to your computer and use it in GitHub Desktop.
Create layers from artboards in illustrator
This file contains hidden or 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
// Script that moves all items from each artboard to a new layer with the same name as the artboard | |
// modified from answer by DilliamWowling | |
// https://community.adobe.com/t5/illustrator-discussions/multiple-artboards-to-multiple-layers/m-p/8922266#M43797 | |
function layersFromArtboards() | |
{ | |
var docRef = app.activeDocument; | |
var layers = docRef.layers; | |
var aB = docRef.artboards; | |
//we will remove this layer after the others have been created. | |
var tempLay = layers[0]; | |
tempLay.name = "Temp"; | |
//loop the artboards | |
for(var x=0;x<aB.length;x++) | |
{ | |
var thisAb = aB[x]; | |
aB.setActiveArtboardIndex(x); | |
docRef.selectObjectsOnActiveArtboard(); | |
var sel = docRef.selection; | |
//create a new layer | |
var newLay = layers.add(); | |
newLay.name = thisAb.name; | |
alert(sel) | |
//loop through the selection and move all artwork onto new layer | |
//this is only necessary if the artwork on a given artboard is not | |
//grouped. This ensures that all the art will be moved, even if there are | |
//multiple ungrouped objects. | |
for(var a=0;a<sel.length;a++) | |
{ | |
myPath = sel[a]; | |
myPath.move(newLay, ElementPlacement.PLACEATEND); | |
} | |
} | |
tempLay.remove(); | |
} | |
layersFromArtboards(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment