Skip to main content
brandonb96942845
Inspiring
December 25, 2020
Question

AE20200: Use multiple style.set expressions - not working

  • December 25, 2020
  • 2 replies
  • 1800 views

Greetings all,

 

I'm trying to make use of the new expressions (in JavaScript mode if that helps) to parent text styles between compositions, but I keep running into problems. I've managed to come up with an expression that works when it's by itself, but when I try to stack them like I've seen others do, I get an error starting with the second line: "style.set[whateverelement] is not a function."

 

What I want to do is return specific values from a single layer of "Caption Layout" and apply them to a text layer in another comp, basically so that all I have to do is edit the text style once in "Caption Layout" and it'll propagate everywhere. Yes I could use this to just copy everything:

 

style = comp("Caption Layout").layer("ONE-Line Caption").text.sourceText.style

 

But that returns ALL values, whether I want them or not, and I need certain things different in the template so I can position things properly (specifically, everything in the template is ALL CAPS but I don't want the child layers to inherit that property).

 

These are the expressions I want to stack, exactly as I'm pasting them into the SourceText layer's expression editor:

style.setFontSize(style=comp("Caption Layout").layer("ONE-Line Caption").text.sourceText.style.fontSize);
style.setFauxBold(comp("Caption Layout").layer("ONE-Line Caption").text.sourceText.style.isFauxBold);
style.setAllCaps(style=comp("Caption Layout").layer("ONE-Line Caption").text.sourceText.style.isAllCaps);
style.setLeading(style=comp("Caption Layout").layer("ONE-Line Caption").text.sourceText.style.leading);
style.setTracking(style=comp("Caption Layout").layer("ONE-Line Caption").text.sourceText.style.tracking);

 

Each of these seems to work individually, but put them all together, even separated by a semicolon, and no matter which one is second, that's the one that kicks back an error. So in this case, it says "style.setFauxBold" is not a function, even though that line works perfectly by itself; if I delete that line, it'll do the same with AllCaps, and so on.

 

I know what I'm missing is probably absurdly simple, but I've been Googling for an hour and I can't figure it out. Help please???

This topic has been closed for replies.

2 replies

aTomician
Inspiring
November 23, 2022

Massive thanks to @Dan Ebberts and other commenters on this, I've been trying for a long time to add more text control into my MOGRTS and now I've stumbled across this post, I've found a way to do it!  I know it's an older post but I wanted to share my expression here which works rather well for me.  Instead of copying an existing style, I've found it easier to create a new, blank style and add all the styles from scratch.

 

 

 

output = "test text here";

newStyle = createStyle()
newStyle = style.setFontSize(50);
newStyle = newStyle.setFauxBold(true);
newStyle = newStyle.setAllCaps(true);
newStyle = newStyle.setLeading(3);
newStyle = newStyle.setTracking(2);
newStyle = newStyle.setFontSize(10);
newStyle = newStyle.setFillColor(fColor);
newStyle = newStyle.setText(output);

 

 

 

Now I just need some textbox size controls and I can make my own Essential Graphics panel in a MOGRT!

 

Here's a list of all the possible style properties:

 

Regards, aTomician
Community Expert
December 28, 2020

From your explanation, I think that you want to be able to choose which styles you want to use from the master comp text layer. This is much easier to accomplish using Extended Graphics than it is going to be by adding and editing expressions. If you want it to be just with expressions that at the very least, you will have to set up checkboxes for each property you want to copy and a bunch of IF statements. If you want to ignore All Caps from the master text layer then you'll need an if statement in the slave layer that says if (All Caps = 0) {style = all caps off} else {style = all caps}. That's obviously not the correct language. I'm not sure it is even possible. Dan Ebberts probably would. I don't think the style functions for text layers are very well developed. You can't specify individual lines of text or individual characters, so it's highly unlikely that you would be able to specify which styles you could copy. 

 

On the other hand, this would be fairly easy to do using Extended Graphics.

 

 

brandonb96942845
Inspiring
December 28, 2020

The reason I need to pick and choose like this is because on in my parent comp, the text needs to be all caps so I can better position it (think of letters like Ps and Gs that hang below the line), but in the child comps they need to be mixed-case so we're not shouting at viewers.

 

I'd really prefer to stick with expressions if at all possible. I know Dan Ebberts is a genuis at this kind of thing, maybe he'll have some inputs on how to solve this.

Dan Ebberts
Community Expert
Community Expert
December 28, 2020

I think this will work:

s = comp("Caption Layout").layer("ONE-Line Caption").text.sourceText.style;
newStyle = style.setFontSize(s.fontSize);
newStyle.setFauxBold(s.isFauxBold);
newStyle.setAllCaps(s.isAllCaps);
newStyle.setLeading(s.leading);
newStyle.setTracking(s.tracking);