3 Replies Latest reply on Sep 9, 2016 6:11 AM by zertle

    Random coloring words

    leszekg66533991

      Hi,

      I have a group of words changed to curves. I would like to whole words got random colors, not as individual letters. It is possible?

      I tried free scprit Random-Swatch-Fill but it doesn't work with groups but idea of action is very similar.

        • 1. Re: Random coloring words
          zertle Level 2

          Hey! Assuming that you have a loop that looks like this

           

          loop through shapes {

               pick random color;

               shape.fillColor = random color;

          }

           

          all you need to do is move the pick random color to before the loop

           

          pick random color;

          loop through shapes {

               shape.fillColor = random color;

          }

           

          If you post the code I can be a bit more specific, but that's the general idea.

          • 2. Re: Random coloring words
            leszekg66533991 Level 1

            Code of Random Swatch Fill

             

            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;

             

              }

              }

            }

            • 3. Re: Random coloring words
              zertle Level 2

              I added some comments

               

              function RandomColor() {
              myDoc = app.activeDocument;  // current document file
              mySelection = app.activeDocument.selection;   // get anything that's selected in the current document
              
              if (mySelection instanceof Array)
              {
                  selSwatches = myDoc.swatches.getSelected();  // get any selected swatches
                  
                  if(selSwatches.length != 0)
                  {
                      ///////////////// This is the big change ///////////////////
                      // select an index at random from our list of selected swatches
                      swatchIndex = Math.round( Math.random() * (selSwatches.length - 1 ));
                      /////////////////////////////////////////////////////////////////////////////
                      
                      // loop through everything that's selected
                      for (i=0; i<mySelection.length; i++)
                      {
                          // if the current item we're checing is either a Path Item or a Compound Path Item
                          if(mySelection[i].typename == "PathItem" || mySelection[i].typename == "CompoundPathItem")
                          {
                              // get the current item from our list of selected items
                              selItem = mySelection[i];
                              selItem.filled = true;
                              
                              // set it's fill color to our random swatch color
                              if(selItem.typename == "PathItem")
                                  selItem.fillColor = selSwatches[swatchIndex].color;
                              else
                                  selItem.pathItems[0].fillColor = selSwatches[swatchIndex].color;
                          }
                      }
                  }
              }
              }
              
              RandomColor();
              

               

              Good luck! :-)