Copy link to clipboard
Copied
Hi
I have a text layer in Adobe Photoshop (it's a text-frame). Suppose I deffined it as a variable called "myText"... by using:
var myText = app.activeDocument.layers.getByName("dados");
In Adobe Illustrator, I can simply use the property: "words" in order to acess an array of all words in the text frame. I could declare anything like:
var countWords = myText.words;
And...after... I can acess the "countWords[1]", "countWords[2]".... to acess all individual words and personalize them.
Looking at Photoshop documentation I did not find similar property or object or instance... In "textItem" object there's no "paragraph" or "words" option that I can try.
Is there any way in Photoshop I can acess individual words in a text frame layer, so I could, for example, chance the color of this word...or increase the size of just this word?
Thank you very much for the help.
Gustavo.
You can change the text parameters for a specific
position and length using this function. The words and their positions in the text will have to be searched for.
...var c1 = new SolidColor();
with (c1.rgb) { red = 200; green = 100; blue = 150; }
var c2 = new SolidColor();
with (c2.rgb) { red = 20; green = 100; blue = 200; }
// activeLayer in demo example must be textlayer
activeDocument.activeLayer.textItem.size = 12;
activeDocument.activeLayer.textItem.contents = "0123456789012345678901234567890";
/
Copy link to clipboard
Copied
Hi Gustavo,
some snippets and or possible ways could be find here: Changing color of text found with regex
Copy link to clipboard
Copied
You can change the text parameters for a specific
position and length using this function. The words and their positions in the text will have to be searched for.
var c1 = new SolidColor();
with (c1.rgb) { red = 200; green = 100; blue = 150; }
var c2 = new SolidColor();
with (c2.rgb) { red = 20; green = 100; blue = 200; }
// activeLayer in demo example must be textlayer
activeDocument.activeLayer.textItem.size = 12;
activeDocument.activeLayer.textItem.contents = "0123456789012345678901234567890";
// examples
set_text_style(0, 4, 50)
set_text_style(4, 4, 70, c1)
set_text_style(10, 5, 30, c2)
function set_text_style(from, len, size, color)
{
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("textLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
var list1 = new ActionList();
var d2 = new ActionDescriptor();
d2.putInteger(stringIDToTypeID("from"), from);
d2.putInteger(stringIDToTypeID("to"), from+len);
var d3 = new ActionDescriptor();
d3.putUnitDouble(stringIDToTypeID("size"), stringIDToTypeID("pointsUnit"), size);
if (color != undefined)
{
var d4 = new ActionDescriptor();
d4.putDouble(stringIDToTypeID("red"), color.rgb.red);
d4.putDouble(stringIDToTypeID("green"), color.rgb.green);
d4.putDouble(stringIDToTypeID("blue"), color.rgb.blue);
d3.putObject(stringIDToTypeID("color"), stringIDToTypeID("RGBColor"), d4);
}
d2.putObject(stringIDToTypeID("textStyle"), stringIDToTypeID("textStyle"), d3);
list1.putObject(stringIDToTypeID("textStyleRange"), d2);
d1.putList(stringIDToTypeID("textStyleRange"), list1);
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("textLayer"), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}
catch (e) { throw(e); }
}
Copy link to clipboard
Copied
Thank you very much pixxxel and r-bin.
It's clear it's not so easy to process, but it's possible to try these codes!
If I find it still difficult to work, perhaps I will pass the code to Illustrator process (script to Illustrator) and use BridgeTalk to process the necessary photos in Photoshop!
Thank you very much
Gustavo.
Copy link to clipboard
Copied
You can add other parameters. Which ones can be found with the help of the ScriptListener plugin.
For example
d3.putBoolean(stringIDToTypeID("styleSheetHasParent"), true);
d3.putString(stringIDToTypeID("fontPostScriptName"), "ArialMT");
d3.putString(stringIDToTypeID("fontName"), "Arial");
d3.putString(stringIDToTypeID("fontStyleName"), "Regular");
d3.putInteger(stringIDToTypeID("fontScript"), 0);
d3.putInteger(stringIDToTypeID("fontTechnology"), 1);
d3.putDouble(stringIDToTypeID("horizontalScale"), 69.1);
d3.putDouble(stringIDToTypeID("verticalScale"), 89,1);
d3.putBoolean(stringIDToTypeID("syntheticBold"), true);
d3.putBoolean(stringIDToTypeID("syntheticItalic"), true);
d3.putBoolean(stringIDToTypeID("autoLeading"), false);
d3.putUnitDouble(stringIDToTypeID("leading"), stringIDToTypeID("pointsUnit"), 8);
d3.putInteger(stringIDToTypeID("tracking"), -10);
d3.putUnitDouble(stringIDToTypeID("baselineShift"), stringIDToTypeID("pointsUnit"), 20);
d3.putEnumerated(stringIDToTypeID("autoKern"), stringIDToTypeID("autoKern"), stringIDToTypeID("opticalKern"));
d3.putEnumerated(stringIDToTypeID("fontCaps"), stringIDToTypeID("fontCaps"), stringIDToTypeID("smallCaps"));
d3.putEnumerated(stringIDToTypeID("digitSet"), stringIDToTypeID("digitSet"), stringIDToTypeID("defaultDigits"));
d3.putEnumerated(stringIDToTypeID("baseline"), stringIDToTypeID("baseline"), stringIDToTypeID("subScript"));
d3.putEnumerated(stringIDToTypeID("strikethrough"), stringIDToTypeID("strikethrough"), stringIDToTypeID("xHeightStrikethroughOn"));
d3.putEnumerated(stringIDToTypeID("underline"), stringIDToTypeID("underline"), stringIDToTypeID("underlineOnLeftInVertical"));
d3.putBoolean(stringIDToTypeID("altligature"), true);
d3.putEnumerated(stringIDToTypeID("textLanguage"), stringIDToTypeID("textLanguage"), stringIDToTypeID("englishLanguage"));
Copy link to clipboard
Copied
How did you generate this list from ScriptingListener detailed that way? There's usually too many random stuff in between
Copy link to clipboard
Copied
Also mostly of the stringIDs come in a four-letter code instead of clean name like that