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

setStyleAt() method for text style expressions

Contributor ,
Feb 05, 2025 Feb 05, 2025

Copy link to clipboard

Copied

Text style expressions are fantastic! But chaining many methods together is verbose.

 

Idea:

Similar to getStyleAt(), I would like a setStyleAt() method.  I want to create a style that contains a bunch of methods, and apply that style to a range.

 

This method should apply a predefined Text Style object to a specified range and optional time.

Parameters: Text Style object, index, time

 

text.sourceText.setStyleAt(style, 0, 0)

 

 

How will the idea help your workflow? 

I find myself chaining many style methods together and needing to individually apply all methods to the same ranges. This creates many lines of code for 1 "look". Example:

 

text.sourceText.style
	.setFillColor(effect("Color Control")("Color"), startIndex, numChars)
	.setFont("Impact", startIndex, numChars)
	.setTracking(5, startIndex, numChars)
	.setAllCaps(true, startIndex, numChars)

 

 

Benefits of Feature:

  1. If setStyleAt() method takes in a style object as a param, we can create multiple text layers with unique styles and pass each style into the method. In this way, you can create a "mixed" text style with varied ranges (ex. collage-style text).
  2. Use createStyle() to hold style attributes, and then apply all attributes to a range with setStyleAt()
  3. This allows you to define a style & reuse it, perfect for templates

 

Enlist support!

Vote on this fix~!

Idea No status
TOPICS
Expressions , Workflow

Views

223
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
2 Comments
Adobe Employee ,
Feb 06, 2025 Feb 06, 2025

Copy link to clipboard

Copied

My Javascript is a little rusty as I don't get to write much code these days, but here's one way to do this as a function:

 

const presetStyle = { 
	setFont : "Athelas-Regular",
	setFontSize : 107,
	setTracking : 0,
	setLeading : 128.400009155273,
	setBaselineShift : 0,
	setApplyFill : true,
	setFillColor : [.5,.3,1,1],
	setApplyStroke : false,
	setStrokeWidth : 1,
	setAllCaps : false,
	setSmallCaps : false,
	setFauxBold : false,
	setFauxItalic : false
}; 

const anotherTextStyleObj = {
	setFontSize: 150,
	setAllCaps: true
};

let textStyle = text.sourceText.style;

function setStyleAt(textStyleObj, startIndex, numChars) {
	for (const [key, value] of Object.entries(textStyleObj)) {
		textStyle = textStyle[key](value, startIndex, numChars);
	}
	return textStyle
}

setStyleAt(presetStyle, 0, 10);
setStyleAt(anotherTextStyleObj, 15, 5);

 

You can even overlap the style ranges and change some but not all of the properties. 

 

I have a script from a few years ago that gets all the available text properties and turns them into an object. I should dig that up, it's more useful now.

 

(Edit: just got a chance to catch your new tutorial on text expressions, awesome job! And keep the requests coming! 😀)

Votes

Translate

Report

Report
Contributor ,
Feb 17, 2025 Feb 17, 2025

Copy link to clipboard

Copied

LATEST

Thanks for the reply @VictoriaNece! That is a wild custom function to see working. And glad you caught the tutorial 🙂

 

I've seen some other home brewed functions. But specifying every value individually and mapping to the methods is the verbose part.  I was envisioning something like:

 

const styleA = thisComp.layer("Style A").text.sourceText.style;
const styleB = thisComp.layer("Style B").text.sourceText.style;

text.sourceText.style
	.setStyleAt(styleA, 0, 10)
	.setStyleAt(styleB, 11, 5)

 

 

Votes

Translate

Report

Report