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);
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
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.
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
.
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])
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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.