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

expression to change charachter font weight

Community Beginner ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

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);

 

TOPICS
Expressions , Scripting

Views

438

Translate

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
LEGEND ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

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 

Votes

Translate

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
Community Beginner ,
Jan 09, 2024 Jan 09, 2024

Copy link to clipboard

Copied

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.

Screenshot 2024-01-09 at 10.43.37.png

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

Screenshot 2024-01-09 at 10.47.48.png

Screenshot 2024-01-09 at 10.48.00.png

Screenshot 2024-01-09 at 10.48.10.png

Votes

Translate

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
Community Expert ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

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])

Votes

Translate

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
Community Beginner ,
Jan 09, 2024 Jan 09, 2024

Copy link to clipboard

Copied

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 ? 

Votes

Translate

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
Community Expert ,
Jan 09, 2024 Jan 09, 2024

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

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