Skip to main content
Participant
January 8, 2024
Question

expression to change charachter font weight

  • January 8, 2024
  • 2 replies
  • 1252 views

I am trying to create a script that would change the font weight of enery charachter from a word randomly every 3 frames?
The differents fonts weights are : light regular medium Semibold bold Black italic
I have found this on the internet but can not make it work : 

var textLayer = this.textLayer;
var currentFontWeight = textLayer.sourceText.fontWeight;
var weights = ["Light", "Regular", "Medium", "SemiBold", "Bold", "Black italic"];
var index = Math.floor(Math.random() * weights.length);

var newFontWeight = weights[index];

setInterval(() => {
textLayer.sourceText.fontWeight = newFontWeight;
}, 3);

 

This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
January 8, 2024

I think a lot of (most?) fonts have the weights build into the font name, so for Myriad Pro, for example, you'd need to do something like this:

weights = ["Cond","CondIt","BoldCond","BoldCondIt","Regular","It","Semibold","SemiboldIt","Bold","BoldIt"];
seed = Math.floor(timeToFrames(time)/3);
seedRandom(seed,true);
idx = Math.floor(random(weights.length));
style.setFont("MyriadPro-" + weights[idx])
Participant
January 9, 2024

Thank you, it works well !
But it changes the font weight of the hole word and I am trying to changes the font weight of  letters by letters randomly. I have tried adapting your code but I can not make it work, do you have an idea on how I could achieve this ? 

Dan Ebberts
Community Expert
Community Expert
January 9, 2024

Unfortunately, there's currently no good way to do that on a per-character basis with an expression. The public beta does provide a way to do it with scripting, but I don't know if that's helpful for your situation.

Mylenium
Legend
January 8, 2024

That code is nonsense. "index" is a reserved keyword and refers to the layer index. It must not be used as a user-defined function or variable name. Also your set interval() function isn't defined anywhere. If you copied this from somewhere, you need to include everything and if it's ripped it will need some polishing as well to work as an expression.

 

Mylenium 

Participant
January 9, 2024

Thank you for your answer, I am new to this and it is not easy to understand everything.

At the moment I have used the "Source text" propriety and have placed keyframe every 3frames, for each Keyframe I have manualy changed the font weigh of random letters in my text layer.

But I have 100 more animation to do with this technique (each with a different word)  and I am looking to make it easier than manualy changing font weight for every animation.

 What I am trying to achieve is to create a preset/script that would make this effects (changing font weight of some letters in my text randomly every 3frames) that I could aply to all the other animations