• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Write used color swatch names as text on the artboard

Community Beginner ,
Dec 05, 2017 Dec 05, 2017

Copy link to clipboard

Copied

Below is a a script that I found in hopes that it would be able to take all of the "used swatches" in the file and write a list of their swatch names in a text box. I work in the Sublimation apparel industry and it would be very useful for art approval documents. The script I found below does not work. I have little to no knowledge on how to edit or customize it to work the way I'd like it to.

 

Any advice, editing, creating of the script so I can download it... would be much appreciated.

 

Thanks in advance!

 

// https://community.adobe.com/t5/illustrator-discussions/write-used-color-swatch-names-as-text-on-the-artboard/m-p/9487666#M73128

function usedSwatches() {

  if (app.documents.length == 0) {

    return;

  } else {

    var docRef = app.activeDocument;

    var docW = docRef.width;

    var docH = docRef.height;

    var sL = docRef.swatches;

    var text = '';

    for (var i = 0; i < sL.length; i++) {

      if (sL[i].name != '[None]' && sL[i].name != '[Registration]') {

        text += sL[i].name + '\r';

      }

    }

    var aP = docRef.pathItems.rectangle(docH, 0, docW / 2, docH, true);

    var tF = docRef.textFrames.areaText(aP);

    tF.contents = text;

  }

}

usedSwatches();
TOPICS
Scripting

Views

847

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 06, 2017 Dec 06, 2017

Swatch names don't need to be enclosed between brackets [ ], except for [None] and [Registration]. Write your swatch names as 'White', 'Black', etc

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

This script only shows the current available swatches in the active document.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

When you run the script, do you get any error messages? What is the result of the script? Is it simply printing the wrong swatches into the text frame? Is a text frame being created?

Can you share an example file so we know exactly how to navigate the file and give the desired result?

The more information you can share about what your needs are, the better we can help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

Below is the file. For example, this file has a wrestling singlet in it that uses customer colors. The script that I posted above I ended up getting to work but I want to modify it so that it doesn't list 'Bright Pink', 'White' and 'Black' too.

 

Screen Shot 2017-12-06 at 7.47.30 PM.png

 

The script already is made to exclude '[Registration]' and 'None' so I tried to copy that for 'BRIGHT PINK', 'White' and 'Black' but it didn't work. As you can see it is still listing them.  Below is the exact script I have in there now...

 

// https://community.adobe.com/t5/illustrator-discussions/write-used-color-swatch-names-as-text-on-the-artboard/m-p/9487666#M73128

function swatchNamesToText() {

  if (app.documents.length = 0) {

    return;

  } else {

    var docRef = app.activeDocument;
    var sel = docRef.selection;
    if (sel.length == 1 && sel[0].typename == 'TextFrame') {

      var nameList = Array();

      var swatGrps = docRef.swatchGroups;

      for (var i = 0; i < swatGrps.length; i++) {

        var grpList = swatGrps[i].getAllSwatches();

        for (var j = 0; j < grpList.length; j++) {

          if (grpList[j].name != '[None]'

            &&
            grpList[j].name != '[Registration]'

            &&
            grpList[j].name != 'BRIGHT PINK - Poly 775' &&
            grpList[j].name != 'White' &&
            grpList[j].name != 'Black') {

            nameList.push(grpList[j].name);

          }

        }

      }

    }

    sel[0].contents = nameList.join(', ');

  }

}

swatchNamesToText();

 

Does it look like I wrote anything wrong or do I need to add something else?

 

Thank you in advance for the help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2017 Dec 06, 2017

Copy link to clipboard

Copied

Swatch names don't need to be enclosed between brackets [ ], except for [None] and [Registration]. Write your swatch names as 'White', 'Black', etc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

Hi. 
I have trouble with this script, all it do is creating empty text frame. What I do wrong?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

try copying the script again it should work now.

 

select a text frame before running the script

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

Is there a way to edit the below to make the name list stacked instead of on one line? 

sel[0].contents = nameList.join(', ');

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

LATEST

Figured it out 

sel[0].contents = nameList.join('\n ');

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines