11 Replies Latest reply on Oct 5, 2012 2:47 PM by CarlosCanto

    Apply every swatch library color to path items on a page

    rootbeerguy

      Hello,

      I'm trying to write a script that applies a single swatch to a single path item and repeat for every swatch that is currently contained in the swatch library. This script that I have written is only applying the last swatch in the swatch library to every path item on the page. Currently I'm more concered with getting each swatch that is currently in the swatch library to be applied at least once before worrying about applying the same patch to any extra number of patch items compared to the swatches.length.

      // Apply every swatch library color to path items on a page
      if ( app.documents.length > 0 && app.activeDocument.pathItems.length > 0 ) {
          doc = app.activeDocument;
          for (var i = 0; i < doc.pathItems.length; i++) {
          pathRef = doc.pathItems[i];
          pathRef.filled = true;
              for (var s = 0; s < doc.swatches.length; s++) {
              pathRef.fillColor = doc.swatches[s].color;
              }
          }
      }