14 Responses to Illustrator CS 5 Script: Distribute To Layer
  1. Indie

    great script! thank you :)

  2. Martin

    Thanks! Works fine in CS 5 as well!

  3. Johan Borgström

    Great! Thanks for letting me know ! :)

  4. Fredrik

    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?

  5. Johan Borgström

    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.

  6. Bryan

    You just made my year.

  7. Johan Borgström

    :)
    Know that feeling, glad to help !

  8. Dan Sollis

    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();
    }

    }

  9. Sylwia

    Works like a charm. Thank you very much.

  10. Johan Borgström

    I am glad that it helps you and you are welcome :)

  11. Mats

    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..

  12. Johan Borgström

    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

  13. Daniel Molina

    Thanks a lot man!

  14. Johan Borgström

    You are welcome ! :)

Leave a Reply

Your email address will not be published. Please enter your name, email and a comment.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>