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

Get list of colors from selection or document swatches

Participant ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Hi community, can you help me up with the following?

This is very related to the thread: https://community.adobe.com/t5/illustrator-discussions/turn-document-swatches-into-colored-text/m-p/...

shoutout to @femkeblanco and @pixxxelschubser for your help in the last thread.

Now I am wondering if I can get the same list, but without coloring the text, it will look like this:

 

AntonioPachecoHN_0-1667941390039.png

it will get the list of colors from swatches (in case it's an image coming from PS already with colors) or from the selection (in case it is a vector), help em to add that "point" in the begining of the text, and... if is not ask for too much, the code would let me change the spacing in teh lines, the font style and color, thank you! Have a nice day.

TOPICS
How to , Scripting , SDK , Tools , Type

Views

132

Likes

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

Advisor , Nov 08, 2022 Nov 08, 2022

This is a hasty change to the preceding script.  See if it does what you want.

// var orientation = "vertical";  // or "horizontal"
var size = 10;
var space = 5;  // horizontal space between textPaths
var font = "ArialMT";  // font
var w = size * 2, h = size, x = 0, y = h + space;
var doc = app.activeDocument;
var swatches = doc.swatches;
var color = swatches["Black"].color;  // color
var group = doc.groupItems.add();
var rect = doc.pathItems.rectangle(- y + h + space, x, w, h);
var text = doc.te
...

Likes

Translate

Translate
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Hi,

If you don't want to color the text then comment the line from the previous code.

text.textRange.fillColor = swatches[i].color;

The above line changes the color of text, if you remove this line or comment it, the color of the text will not change.

 

Best regards

Likes

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
Participant ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Thank you Charu, now trying to figure out how to change the font style in the text frame and also add that "dots" in the begining.

Likes

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
Participant ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

I tried this, because I found a function that assigns a font style and size to my textframe, here it is:\

 

var orientation = "vertical"; // or "horizontal"
var roman = make_style('roman', 'ArialMT', 15.2448);
var size = 15.2448;//size font
var w = size * 5, h = size, x = 160, y = 262; // width, height, left and top
var doc = app.activeDocument;
var swatches = doc.swatches;
var group = doc.groupItems.add();
for (var i = 2; i < swatches.length; i++) {
var rect = doc.pathItems.rectangle(y, x, w, h);
var text = doc.textFrames.areaText(rect);
text.contents = swatches[i].name;
//text.textRange.fillColor = swatches[i].color;
roman.applyTo(text.textRange, true);
while (text.lines[0].characters.length < text.characters.length) {
text.textPath.width += size;
}
if (orientation == "horizontal") x += text.textPath.width;
if (orientation == "vertical") y -= h;
text.move(group, ElementPlacement.PLACEATEND);
}

//The function I found
function make_style(style_name, font_name, size) {
var doc = app.activeDocument;
try { var style = doc.characterStyles.add(style_name) }
catch(e) { var style = doc.characterStyles.getByName(style_name) }
style.characterAttributes.size = size;
style.characterAttributes.textFont = textFonts.getByName(font_name);
return style;
}

 

But still I don'w knwo how to change the color of the text frame and neither how to add that dot in the begining, I found somethng in paragraph but recording an action is not working when I run it again in a different group/list of colors.

 

AntonioPachecoHN_0-1667944025707.png

 

Likes

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
Advisor ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

This is a hasty change to the preceding script.  See if it does what you want.

// var orientation = "vertical";  // or "horizontal"
var size = 10;
var space = 5;  // horizontal space between textPaths
var font = "ArialMT";  // font
var w = size * 2, h = size, x = 0, y = h + space;
var doc = app.activeDocument;
var swatches = doc.swatches;
var color = swatches["Black"].color;  // color
var group = doc.groupItems.add();
var rect = doc.pathItems.rectangle(- y + h + space, x, w, h);
var text = doc.textFrames.areaText(rect);
text.contents = "Fabric COLORS";
text.textRange.size = size;
text.textRange.textFont = textFonts[font];
text.textRange.fillColor = color;
while (text.lines[0].characters.length < text.characters.length) {
    text.textPath.width += size;
}
text.move(group, ElementPlacement.PLACEATEND);
for (var i = 2; i < swatches.length; i++) { 
    var rect = doc.pathItems.rectangle(- y, x, w, h);
    var text = doc.textFrames.areaText(rect);
    text.contents = "\u2022 " + swatches[i].name;
    text.textRange.size = size;
    text.textRange.textFont = textFonts[font];
    text.textRange.fillColor = color;
    while (text.lines[0].characters.length < text.characters.length) {
        text.textPath.width += size;
    }
    // if (orientation == "horizontal") x += text.textPath.width;
    // if (orientation == "vertical") y += h + space;
    y += h + space;
    text.move(group, ElementPlacement.PLACEATEND);
}

 

Likes

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
Advisor ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

The string for the "dot" is "\u2022".  For a list of font names, see here.

Likes

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
Participant ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

Thank you very much! That was the correct answer, but I would like to ask... If is possible to assign a color (whether cmyk or rgb) from the code instead of looking in the swatches? thanks!

Likes

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
Participant ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

I found it! is is something like:

 

var textgray = new CMYKColor();
textgray.cyan = 0;
textgray.magenta = 0;
textgray.yellow = 0;
textgray.black = 50;

Likes

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
Advisor ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

Yes, then assign textgray to text.textRange.fillColor.  There is a similar constructor for RGB.  

Likes

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
Participant ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Sorry for bothering, can you tell me how to change the fotn style from ArialMT to Bebas Neue Regular? I try typing that same name but nothing, thanks!

Likes

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 ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Scripting uses the fonts internal name. 

To find out what the name is, select a text frame with the font you need then run the below script

alert(selection[0].textRange.characterAttributes.textFont);

Likes

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
Participant ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much!

Likes

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