Skip to main content
Known Participant
October 9, 2023
질문

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

  • October 9, 2023
  • 3 답변들
  • 1843 조회

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

이 주제는 답변이 닫혔습니다.

3 답변

c.pfaffenbichler
Community Expert
Community Expert
October 10, 2023

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.) 

Miamore작성자
Known Participant
October 10, 2023

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)

c.pfaffenbichler
Community Expert
Community Expert
October 11, 2023
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) {};
};

 

Legend
October 10, 2023
Miamore작성자
Known Participant
October 10, 2023

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

 

Bojan Živković11378569
Community Expert
Community Expert
October 10, 2023

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