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

Can I automatically color every subsequent letter with a different color selecting a swatch group?

Community Beginner ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

Hello, 

 

I'm searching help for a task, I want to generate a batch of text images in which each individual letter is colored differently. If I create a text and then put a different color on each letter there is no problem but if I want to use variables to produce different text it applies the same effect of the first letter to the full text, this is forcing me to enter each file and re color each letter. I'm curious if there's a method or a script to automatically ensure that each successive letter in every text image receives a unique color. For example, I want the first letter of the text to be bleu, second to be orange, thirt to be green, and then it repeats, forth letter to be bleu, fifth to be orange, sixth to be green, etc

Also, I would like to color the text selecting a swatch group if this is possible.

 

For example:

The Bank

 

Thank you in advance

TOPICS
Actions and scripting

Views

784

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
Adobe
Community Expert ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

I will tag a few experts who will provide the correct answer and may be able to assist you @c.pfaffenbichler @Stephen_A_Marsh 

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
Guide ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

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 ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Hi, this is not exactly what I am searching but it's a workaround, only that for this script I need to create a separated script for every swatch group that I want to use and, with this script it is taking in account the "spaces" as characters, so its trying to color the spaces, is there a way to avoid this "spaces issues"? To explain:

This scipt do this:

The Bank

Instead of this:

The Bank

 

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 ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

DOM code cannot do that, that needs AM code. 

Did @jazz-y ’s post already solve the issue? 

 

If not please explain the Swatch Group issue with the help of screenshots. (I am not sure this is [easily] possible anyway.) 

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 ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Hi, this is not exactly what I am searching, it is a workaround but it has a "space issue" like I posted in jazz's answer, and also its not by selecting swatches (in illustrator to colirize by selecting the swatches group is possible with a script, dont know if in photoshop too)

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 ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Like after select that swatch group, to run a script that will add the color to each letter

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 ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

quote

 (in illustrator to colirize by selecting the swatches group is possible with a script, dont know if in photoshop too)

Just another one of the reasons why doing type-work in Photoshop is a bad idea when one has Illustrator available anyway. 

 

This Script should apply the colors from an Array of color-Arrays and should disregard spaces; collecting the values from a Swatches Group does not seem terribly interesting to me at current. 

 

// apply colors from array to letters of selected type layer;
// 2019, use it at your own risk;
if (app.documents.length > 0) {
//////////////////
try {
var theFonts = new Array;
var theStyleRanges = new Array;
// get font of active layer;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
var theName = layerDesc.getString(stringIDToTypeID('name'));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var hasText = layerDesc.hasKey(stringIDToTypeID("textKey"));
if (hasText == true) {
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var theText = textDesc.getString(stringIDToTypeID('textKey'));
//var shapeList = textDesc.getList(stringIDToTypeID('textShape'));
var paragraphRangeList = textDesc.getList(stringIDToTypeID('paragraphStyleRange'));
var kernRange = textDesc.getList(stringIDToTypeID('kerningRange'));
var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
// process the list;
for (var o = 0; o < rangeList.count; o++) {
var thisList = rangeList.getObjectValue(o);
var theFrom = thisList.getInteger(stringIDToTypeID('from'));
var theTo = thisList.getInteger(stringIDToTypeID('to'));
var styleDesc = thisList.getObjectValue(stringIDToTypeID('textStyle'));
var aSize = styleDesc.getUnitDoubleValue(charIDToTypeID( "Sz  " ));
// check for default font;
if (styleDesc.hasKey(stringIDToTypeID('fontPostScriptName')) == true) {var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'))}
else {
	var theDefault = styleDesc.getObjectValue(stringIDToTypeID('baseParentStyle'));	
	var aFont = theDefault.getString(stringIDToTypeID('fontPostScriptName'));
	};
if (styleDesc.hasKey(stringIDToTypeID('impliedFontSize')) == true) {var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'))}
// add to array;
theFonts.push([aFont, aSize, theFrom, theTo]);
theStyleRanges.push(thisList.getObjectValue(stringIDToTypeID('textStyle')));
}
}
};
// the color array;
var theColors = [[255,0,0], [255,255,0], [0,255,0],[0,255,255], [0,0,255], [255,0,255]];
var anIndex = 0;
var theColorNumber = theColors.length;
// change text;
// =======================================================
var idPxl = charIDToTypeID( "#Pxl" );
var idTxtt = charIDToTypeID( "Txtt" );
var idFrom = charIDToTypeID( "From" );
var idT = charIDToTypeID( "T   " );
var idTxtS = charIDToTypeID( "TxtS" );
var idTxLr = charIDToTypeID( "TxLr" );
var idTxt = charIDToTypeID( "Txt " );
var idsetd = charIDToTypeID( "setd" );
    var desc6 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        ref1.putEnumerated( idTxLr, charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt"  ));
    desc6.putReference( idnull, ref1 );
        var desc7 = new ActionDescriptor();
        desc7.putString( idTxt, theText );
            var list2 = new ActionList();
//////////////////
// define each letter individually;
var theIndex = 0;
var theRef = theStyleRanges[theIndex];
var theRef2 = theFonts[theIndex];
for (var m = 0; m < theText.length; m++) {
// check for relevant style range;
		if (m == theRef2[3]) {
			theIndex++;
			var theRef = theStyleRanges[theIndex];
			var theRef2 = theFonts[theIndex];
			};
		var desc14 = new ActionDescriptor();
		desc14.putInteger( idFrom, m );
		desc14.putInteger( idT, m+1 );
		var theStyle = theRef;
		var desc21 = new ActionDescriptor();
		desc21.putDouble( charIDToTypeID( "Rd  " ), theColors[anIndex][0] );
		desc21.putDouble( charIDToTypeID( "Grn " ), theColors[anIndex][1]  );
		desc21.putDouble( charIDToTypeID( "Bl  " ), theColors[anIndex][2]  );
		theStyle.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), desc21 );
		desc14.putObject( stringIDToTypeID('textStyle'), stringIDToTypeID('textStyle'), theStyle);
		list2.putObject( charIDToTypeID( "Txtt" ),  desc14);
anIndex++;
if (theText[m].match(/\s/)!=null) {anIndex--};
if (anIndex == theColorNumber) {anIndex = 0};
		};
//////////////////
var list3 = new ActionList();
for (var n = 0; n < kernRange.count; n++) {
var thisOne = kernRange.getObjectValue(n);
$.writeln (n+"___"+thisOne.getInteger(charIDToTypeID("From"))+"___"+thisOne.getInteger(charIDToTypeID( "T   " ))+"___"+thisOne.getInteger(stringIDToTypeID("kerning")))
var desc15 = new ActionDescriptor();
desc15.putInteger( idFrom, thisOne.getInteger(charIDToTypeID("From")) );
desc15.putInteger( idT, thisOne.getInteger(charIDToTypeID( "T   " )) );
desc15.putInteger( charIDToTypeID( "Krng" ), thisOne.getInteger(stringIDToTypeID("kerning")));
list3.putObject( stringIDToTypeID( "kerningRange"),  desc15);
};
        desc7.putList( idTxtt, list2 );
        desc7.putList( stringIDToTypeID( "kerningRange"), list3);
    desc6.putObject( idT, idTxLr, desc7 );
executeAction( idsetd, desc6, DialogModes.NO );
}
catch (e) {};
};

 

Screenshot 2023-10-11 at 12.10.12.pngScreenshot 2023-10-11 at 12.10.21.png

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 ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

Thank you! Just want to know if  the script will work with hexadecimal color codes? Its what I normally use, also, where should I remplace these colors exactly please? In the top line? If its not in the top line, could it be there? (will be easier to access). I have tested and its coloring in that RGB swatch example, but not sure where I should update the color codes to use a new palette.

And yes, I tried to work with illustrator but I am kind of new to it and for what I know it is not possible to link svg images and add effects, only if its embeded, so I cant use it for what I need.

Thank you in advance 🙂

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 ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

For example if I would like to use this codes: 

004fab, 00cfb3, ff7000, 14a41c

 

thank you!

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 ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

quote

For example if I would like to use this codes: 

004fab, 00cfb3, ff7000, 14a41c

 

thank you!


By @Miamore

 

Untested, but have you tried changing the code from @c.pfaffenbichler ?

 

From:

 

// the color array;
var theColors = [[255,0,0], [255,255,0], [0,255,0],[0,255,255], [0,0,255], [255,0,255]];

 

To:

 

// the color array;
var theColors = [004fab, 00cfb3, ff7000, 14a41c, ce007d, 2900e7];

 

P.S. I am not sure if you need to enclose the hex values in quotes, such as "004fab" (and I don't believe that you should prefix the # symbol).

 

Otherwise, just use the sRGB equivalent values.

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 ,
Oct 12, 2023 Oct 12, 2023

Copy link to clipboard

Copied

Hi, its giving me an error if I replace that part, "Error 6: Bad digit in number. Line 46" (the one that I replaced). This script does almost the same as the one suggested by Jazz-y, but this one dont use hexadecimal color codes (and are not easy to reach because I need to change them often, I dont know a lot about scipting, so dont know if I can just put that line on top), and the script suggested by Jazz-y is trying to color the spaces but the good thing is that it is using hexadecimal color codes (I work with that and its better to paste for example only 5 codes instead of 15). I have almost what I need with both scripts but sadly not 100% 😞

 

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 ,
Oct 12, 2023 Oct 12, 2023

Copy link to clipboard

Copied

I didn't see the code from jazz-y. So why don't you use that as a guide?

 

Looking at that topic link, the values do need to be wrapped in quotes, so:

 

// the color array;
var theColors = ["004fab", "00cfb3", "ff7000", "14a41c", "ce007d", "2900e7"];

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 ,
Oct 13, 2023 Oct 13, 2023

Copy link to clipboard

Copied

I have tried but with quotes it does nothing when I run 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
Community Expert ,
Oct 14, 2023 Oct 14, 2023

Copy link to clipboard

Copied

LATEST

Obviously you need to adapt the code that applies the color if you insist on using hex-numbers. 

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