3 Replies Latest reply: Apr 6, 2012 3:37 PM by Larry G. Schneider RSS

    Getting swatch names of each document item

    thor2112

      I'm trying to find a way to loop thru all items in an Illustrator document and get their stroke and fill color.  Sometimes items are spots, sometimes documents are set to RGB or CMYK, etc, so swatches can be a mixture of things.  Is there an easy way to get the swatch name for each item?

       

       

      For example, I can check if an item is a spot, and get it's color like so:

       

       

      var c = app.activeDocument.pageItems[0];

       

      if (c.strokeColor.typename === 'SpotColor') {

          var s = c.strokeColor.spot.name;

      }

       

       

      But if I try to get the name from an item colored 'Black' (which is set to Process Color, CMYK), then I'll need to do something else like:

       

       

      var c = app.activeDocument.pageItems[0];

       

      if (c.strokeColor.typename === 'CMYKColor') {

          var s = c.strokeColor.name;  // This returns undefined - not sure what I'm doing!!!

      }

       

       

      Is there an easier way to achieve this, other than getting the typename of each item, and then trying to figure out it's color name?  I was hoping something like this would work:

       

      var c = app.activeDocument.pageItems[0].strokeColor.name;

       

       

      Thanks!

       

       

      Jay