Skip navigation
Currently Being Moderated

Getting swatch names of each document item

Apr 6, 2012 7:41 AM

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 =;




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 =;  // 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];







  • Currently Being Moderated
    Apr 6, 2012 9:00 AM   in reply to thor2112

    In AI you can mix a color at any time and not have to add it to the swatch list. It will only work if you have made a swatch for each color used in the file. One way would be to use the Add Used Colors from the Swatch panel flyout menu to add all the colors to the Swatches panel.

    Mark as:
  • Currently Being Moderated
    Apr 6, 2012 3:37 PM   in reply to thor2112

    If you use the Add Used Colors, the colors will be added as Global colors with the name being the CMYK numbers (to whole percents)

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points