Skip navigation
Currently Being Moderated

Crazy Scripting Help

May 30, 2012 6:09 PM

Tags: #javascript #scripting

I’ve created a group of 40 different icons (telephone, star, diamond, etc.) and I need to apply 150 colors to each one of those icons then save each icon individually as a PNG with a filename of <ICONNAME-COLORNAME.png>. Those 150 colors have already been defined with individual custom color names within a color group I created called “MyColors.”

 

I’ve figured out the PNG export part of the javascript (and that script is available all over the place) but my scripting skills suck and I’m not sure what I need to do to get this done. I’ve read the Illustrator Scripting Guide (I got lost pretty quick) and I’ve done some searching for scripts but without any luck. I was thinking that the best way to approach this was to put each of the different icons (telephone, star, diamond, etc.) on a single layer, each within a different illustrator file and then run the script on each file to automatically generate the colors and layers I need within each file. I could then run a PNG export script against each file. Or is there a better way to create these PNGs?

 

I know it’s a lot to ask and I hate to ask it, but I’ll lose my mind if I have to do this by hand. Can anyone help me with this scripting? I’d be happy to throw a few bucks your way (or donate them to the charity of your choice)!

 

I'm on Illustrator CS5/CS6 ...

 
Replies
  • Currently Being Moderated
    May 31, 2012 2:59 AM   in reply to RobGreer

    A sample document will help a lot to figure out what you want.

    How can you apply pure color to each one of those icons, your icons are single colored(Monochrome)?

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 5:32 AM   in reply to RobGreer

    You should be able to do this any how multi-docs, mulit-layered doc or multi-artbaord doc… Its a scriptable exercise… More info?

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 10:17 AM   in reply to RobGreer

    You example is very basic ( a single path item )… I don't see any need to create layers of the colors options you could just change the color contents of your items on the fly and output *.png all in a loop. How complex is the artwork in question all like this?

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 11:52 AM   in reply to RobGreer

    Im not sure how you set up your files but given this situation I would… Have 1 doc with all the colors 150 in swatches. 40 layers for icons above a base ( button layer ) then I would…

     

    Turn off every layer

    turn on first layer and change color and export

    then change it to white

    turn on last layer and change color and export

    rinse repeat til done…

     

    does that make sense? 12k pngs

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 3:02 AM   in reply to RobGreer

    1. When you add a new layer, the layers.length changed, and "var oldLayer = layers[i];" will always point to the wrong layer. So you should store origin layers to an Array first.

    2. for (var k = 0; k < oldLayer.pathItems; k++) should be for (var k = 0; k < oldLayer.pathItems.length; k++)

    3. oldLayer.name = oldLayer.name; ???

    4. nLayer.pathItems[k].selected = true; In script you do not need to select object first in order to change color.

     

    So, here you go:

     

    var docRef = app.activeDocument;
    with(docRef) {
        var grp = swatchGroups.getByName('Rob');
        var grpList = grp.getAllSwatches();
        var originalLayerLength = layers.length;
        var oldLayers = [];
        for (var i = 0; i < originalLayerLength; i++) {
            oldLayers[i] = layers[i];
        }
        for (var i = 0; i < oldLayers.length; i++) {
            var oldLayer = oldLayers[i];
            oldLayer.visible = true;
            for (var j = 0; j < grpList.length; j++) {
                var nLayer = layers.add();
                nLayer.name = oldLayer.name + '-' + grpList[j].name;
                for (var k = 0; k < oldLayer.pathItems.length; k++) {
                    oldLayer.pathItems[k].duplicate(nLayer, ElementPlacement.PLACEATBEGINNING).fillColor = grpList[j].color;
                }
            }
        }
    }
     
    

    I can not test because I have no document like you have.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points