I needed to distribute some items in Illustrator CS 5 to separate layers, so I wrote this little script to speed up the workflow. Feel free to download ! : )
Cheers, Johan
jb_distribute_to_layers_v1.1.jsx (346)
I needed to distribute some items in Illustrator CS 5 to separate layers, so I wrote this little script to speed up the workflow. Feel free to download ! : )
Cheers, Johan
jb_distribute_to_layers_v1.1.jsx (346)
14 Responses to Illustrator CS 5 Script: Distribute To Layer
Indie May 23, 2011
great script! thank you :)
Martin August 2, 2011
Thanks! Works fine in CS 5 as well!
Johan Borgström August 2, 2011
Great! Thanks for letting me know ! :)
Fredrik August 5, 2011
I found one problem with the script when using it. I have about 140 groups of objects that I want to distribute to layers but when doing so they totally loose their level depth. This makes for a lot of manual work anyway. It also makes layers that should be close to each other really hard to find in for example AE.
Have you experienced this problem?
Johan Borgström August 9, 2011
Hi ! I just wrote the script when I needed to export some simple vector shapes to afx. I have not really tried it with something more complex. Having tasted the yummy flavor of coding in python I dread going back to javascript and adobe. I wish that Adobe would open up their programs more for the casual art coder person with a nice language like python.
Bryan August 26, 2011
You just made my year.
Johan Borgström August 26, 2011
:)
Know that feeling, glad to help !
Dan Sollis December 14, 2011
Hey, this is an awesome script for people like me who need to animate Illustrator files in After Effects. The only problem – and it is a big problem – is that it appears that the layer order gets reversed. I can fix this in After Effects using another script, but it’d be great to get it working properly in this version.
I’ve been tinkering with it myself (already added some niceties like a “pad digits function” – so layers are always numbered tidily), but so far, no joy. I’ve tried reversing the order the main loop traverses the selectedLayers index, but that doesn’t seem to affect the end result.
Here’s my latest version:
/*
Author: Johan Borgström
Web: http://www.theshapeofmotion.com
Name: jb_distribute_to_layers.jsx
Date: 2010 01 19
Version: 1.0
Function: Distributes the selected items to new layers.
Arguments: None
Return Value: None
*/
try
{
if (app.documents.length > 0 ) main();
else throw new Error(‘There are no document open!’);
}
catch(e)
{
alert( e.message, “Script Alert”, true);
}
// lil “Pad digits” function
function padDigits(n, totalDigits)
{
n = n.toString();
var pd = “”;
if (totalDigits > n.length)
{
for (v=0; v < (totalDigits-n.length); v++)
{
pd += "0";
}
}
return pd + n.toString();
}
// function: number of digits in a number – force number to a string then get length
function numberOfDigits(n) {
return Number(String(n).length);
}
function main()
{
var myProject = app.project; // declare the project name
var myDoc = app.activeDocument;
var mySelectArray= myDoc.selection;
displayWindow();
function displayWindow()
{
myWidth = 200;
myHeight= 110;
dlg = new Window('dialog', 'Distribute to Layers');
dlg.size = [myWidth, myHeight];
dlg.panel = dlg.add('panel', undefined, 'Layer Name');
dlg.layerName = dlg.panel.add('edittext', undefined,undefined); // editable text
dlg.layerName.preferredSize = [myWidth-60,20];
dlg.btn = dlg.panel.add('button', undefined, 'Distribute '); // btn
dlg.btn.alignment = 'left';
dlg.btn.onClick = doDistribute;
dlg.show();
}
function doDistribute()
{
if (dlg.layerName.text < 1)
{
alert('Please give me a Layer Name !');
return;
}
if (mySelectArray.length < 1)
{
alert('Please Select some Items to Distribute !');
return;
}
var totalLayers = Number(mySelectArray.length);
var numberOfLayerNameDigits = numberOfDigits(totalLayers);
for ( i = 0; i < totalLayers; i++ )
{
var newLayer = myDoc.layers.add();
var targetObjectIndex = (-1 + totalLayers – i);
var mySelName = mySelectArray[targetObjectIndex].name;
newLayer.name = (dlg.layerName.text+'_'+ padDigits(targetObjectIndex,numberOfLayerNameDigits));
mySelectArray[i].move(newLayer,ElementPlacement.PLACEATBEGINNING);
}
dlg.close();
}
}
Sylwia January 22, 2012
Works like a charm. Thank you very much.
Johan Borgström January 23, 2012
I am glad that it helps you and you are welcome :)
Mats February 17, 2012
Is there a fix so that you can abort the script if you make the mistake of not having anything selected while activating the script? done it by accident a couple of times, and it locked illustrator for me..
Johan Borgström February 23, 2012
Hi,
The script should check and abort if you havn´t selected anything. I did a change to the script so that happens earlier then before. Hopefully that works :)
I have tested it in CS5.
BR, Johan
Daniel Molina April 17, 2012
Thanks a lot man!
Johan Borgström April 19, 2012
You are welcome ! :)