How can I randomly color paths?

I have a couple hundred paths in one image.

Example of many paths

Is there a tool in Illustrator that would allow me to select a few (10) colors, and then using those colors to randomly fill all my paths.

An example would be a military camouflage pattern


There’s a tool in Illustrator called Recolor Artwork (However I don’t believe that this solves my dilemma)

Recolor Artwork Symbol

Recolor Artwork Panel

I’m not exactly sure how this tool works. I believe that it recolors the artwork, meaning that if all of your paths are already colored in, you can “randomly” change their colors.

I’m looking for a way to do the first step (once I have all my paths filled, I can use the Recolor Artwork in order to change hues etc.)

Edit:

So I’ve found multiple different scripts that accomplish this (and they do it quite well), but I’m still curious if there’s a way to do it within Illustrator, since running the scripts is kind of a hassle – and if I want to reset my colors, I have to do it again. (is there a way I can make it into an action?)

Answer

There is a free script from Vector boom which accomplishes this task.

mySelection = app.activeDocument.selection;
myDoc = app.activeDocument;
if (mySelection instanceof Array)
{
    selSwatches = myDoc.swatches.getSelected();
    
    if(selSwatches.length != 0)
        for (i=0; i<mySelection.length; i++)
        {
            if(mySelection[i].typename == "PathItem" || mySelection[i].typename == "CompoundPathItem")
            {
                selItem = mySelection[i];
                selItem.filled = true;

                swatchIndex = Math.round( Math.random() * (selSwatches.length - 1 ));
                
                if(selItem.typename == "PathItem")
                    selItem.fillColor = selSwatches[swatchIndex].color;
                else
                    selItem.pathItems[0].fillColor = selSwatches[swatchIndex].color;
                
            }
        }
}

You can also easily change fillColor to strokeColor (which I did and now have 2 independent scripts, one for each)


Script usage:

  • Select your paths to be filled

enter image description here


  • Ctrl + click and select all your swatches you want to use

enter image description here


  • Run the script

Result:

enter image description here

Attribution
Source : Link , Question Author : WELZ , Answer Author : Community

Leave a Comment