• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Crazy Scripting Help

Community Beginner ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , May 31, 2012 May 31, 2012

1. When you add a new layer, the layers.length changed, and "var oldLayer = layers;" 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.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) {

    v

...

Votes

Translate

Translate
Adobe
Enthusiast ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

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)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

All of the icons are monochrome. Here is an image that may help explain what I need. The icon in this example (figure 1) is a star. The color group (figure 2) is called "Rob" and each color is named (e.g. gold, gray, red, etc.). I need a script that will take a basic monochrome icon and then create a new layer for every color in that color group with a naming convention of ICONNAME-COLORNAME (e.g. star-gold) and then apply the appropriate color to the icon on that layer. In the end, the final output should look something like the layers seen in figure 3. Is that helpful?

example.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

Yes. The icons themselves are all this simple but there's another wrinkle that I didn't want to mention because I was afraid it would make this question more confusing.

In addition to these simple icons I also need a color button version for each of them. For example, in addition to color icons as previously described, I also need a button in each of the ~150 colors with a white icon (star in this example) on top.

This button is comprised of two objects but when grouped and a color is selected, it changes to the appropriate color needed. Anyway, my plan was to generate the color icons first and save them in a file. I was then going to generate the color buttons the same way (treating them like the icons). Then I was going to paste the icons onto the blank buttons and then move them into the same file as the icons and then generate the PNGs from that single file. I was going to use a naming convention of <ICONNAME-COLORNAME-btn.png> for the button files. Therefore, just doing an export straight to a file wouldn't be my ideal in this situation.

example2.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

Let me simplify my request.

I need a script that will take an object on the first (and only layer) and then create x layers (with x being the total number of colors in the color group) with each layer named for the first layer name (e.g. star) plus the "-COLORNAME" (e.g. -red) to give me x layers with a layer naming convention of FIRSTLAYERNAME-COLORNAME (e.g. star-red).

I can do the rest manually.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

So I got this far but the layer objects aren't duplicating. Any ideas?

var docRef = app.activeDocument;

with (docRef) {

var grp = swatchGroups.getByName('Rob');

/*

for (var i = 0; i < swatchGroups.length; i++) {

    if (swatchGroups.name == 'Rob') {

        grp = swatchGroups;

    }

}

*/

var grpList = grp.getAllSwatches();

//var sw = grpList[55];

var originalLayerLength = layers.length;

for (var i = 0; i < originalLayerLength; i++) {

var oldLayer = layers;

oldLayer.name = oldLayer.name;

oldLayer.visible = true;

    for (var j = 0; j < grpList.length; j++) {

        var nLayer = layers.add();

        nLayer.name = oldLayer.name + '-' + grpList.name;

        nLayer.visible = true;

        for (var k = 0; k < oldLayer.pathItems; k++) {

            oldLayer.pathItems.duplicate(nLayer,

ElementPlacement.PLACEATBEGINNING);

        }

        for (var k = 0; k < nLayer.pathItems.length; k++) {

            nLayer.pathItems.selected = true;

            nLayer.pathItems.fillColor = grpList.color;

        }

    }

}

/*

   for(var i = 0; i < pathItems.length; i++) {

    pathItems.selected = true;

        pathItems.fillColor = sw.color;

    }

*/

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

I should clarify that the new layers are created with the appropriate layer names but there is nothing on the layer. The object isn't copying. Every reference I was able to find said to do it this way so I know I'm missing something basic.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

1. When you add a new layer, the layers.length changed, and "var oldLayer = layers;" 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.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 = layers;

    }

    for (var i = 0; i < oldLayers.length; i++) {

        var oldLayer = oldLayers;

        oldLayer.visible = true;

        for (var j = 0; j < grpList.length; j++) {

            var nLayer = layers.add();

            nLayer.name = oldLayer.name + '-' + grpList.name;

            for (var k = 0; k < oldLayer.pathItems.length; k++) {

                oldLayer.pathItems.duplicate(nLayer, ElementPlacement.PLACEATBEGINNING).fillColor = grpList.color;

            }

        }

    }

}

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

LATEST

That works perfectly! Thanks a bunch! You rock!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 31, 2012 May 31, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines