Skip to main content
Inspiring
April 29, 2025
Answered

In a script, how do you apply a character style to a TextItem?

  • April 29, 2025
  • 1 reply
  • 191 views

I have a valid CharacterStyle, but I can't find the property in a TextFrameItem to apply it to. I've tried applying it to the TextFrameItem, its contents, and its characters properties, and the script quits in all cases.

 

I can't find any example online, either. Any insight appreciated.

 

		style = sourceDoc.characterStyles.getByName("AValidStyle);

		if (!style)
			// couldn't find style in sourceDoc
			continue;

		// create a temporary page item
		var tempTextItem = activeDocument.textFrames.add();
		tempTextItem.contents = "1";
		style.applyTo(tempTextItem.contents);  // NOPE

 

Correct answer Thomas_Calvin

Well, to answer my own question, I finally found that it's the textRange property.

1 reply

Thomas_CalvinAuthorCorrect answer
Inspiring
April 29, 2025

Well, to answer my own question, I finally found that it's the textRange property.