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();
Swatch names don't need to be enclosed between brackets [ ], except for [None] and [Registration]. Write your swatch names as 'White', 'Black', etc
Copy link to clipboard
Copied
This script only shows the current available swatches in the active document.
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.
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.
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.
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
Copy link to clipboard
Copied
Hi.
I have trouble with this script, all it do is creating empty text frame. What I do wrong?
Copy link to clipboard
Copied
try copying the script again it should work now.
select a text frame before running the script
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(', ');
Copy link to clipboard
Copied
Figured it out
sel[0].contents = nameList.join('\n ');