Skip to main content
fajota
Known Participant
March 23, 2023
Answered

Select Font Family and Font Weight with script

  • March 23, 2023
  • 2 replies
  • 601 views

Hello!

I'd like to mix the script that choose font weights plus the script that choose font family.

 

Script  to choose Font Weight:

var fontWeights = [
'Regular',
'Bold',
];
family = thisProperty.style.font;
family = family.split('-');
select = Math.round(clamp(effect("Select Weight")("Slider"), 0, fontWeights.length - 1));
createStyle().setFont(family[0] + '-' + fontWeights[select]);

 

Script to choose Font Family:

var fontArray = [
"Arial",
"Trebuchet MS",
"Times New Roman"
];
v = Math.round(effect("Select Font")("Slider"));
style.setFont(fontArray[v]);

 

Can you help me?

This topic has been closed for replies.
Correct answer Dan Ebberts

There doesn't seem to be a good algorithm for turning a font name into the bold version of that font name, so I think something like this is probably as close as you can get:

fonts = ["ArialMT","TrebuchetMS","TimesNewRomanPSMT"];
boldFonts = ["Arial-BoldMT","TrebuchetMS-Bold","TimesNewRomanPS-BoldMT"];

fontSelect = clamp(Math.round(effect("Select Font")("Slider")),0,fonts.length-1);
weightSelect = clamp(Math.round(effect("Select Weight")("Slider")),0,1);

fontName = weightSelect > 0 ? boldFonts[fontSelect] : fonts[fontSelect];
style.setFont(fontName)

2 replies

Adobe Employee
November 21, 2023

@Dan Ebberts is correct - fonts are not generically structured in the way that you are trying to use them.

 

In the end of course with font property you have to select the PostScript name you desire, and at the time you wrote this that was not easy to figure out.

 

However, now with app.fonts in 24.0 you can browse all the fonts installed on your system and identify the families and faces available in each of them.

 

You can read about that here: https://ae-scripting.docsforadobe.dev/other/fontsobject.html

 

Douglas Waterfall

After Effects Engineering

fajota
fajotaAuthor
Known Participant
April 3, 2023

Anyone can help me? Please!

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 3, 2023

There doesn't seem to be a good algorithm for turning a font name into the bold version of that font name, so I think something like this is probably as close as you can get:

fonts = ["ArialMT","TrebuchetMS","TimesNewRomanPSMT"];
boldFonts = ["Arial-BoldMT","TrebuchetMS-Bold","TimesNewRomanPS-BoldMT"];

fontSelect = clamp(Math.round(effect("Select Font")("Slider")),0,fonts.length-1);
weightSelect = clamp(Math.round(effect("Select Weight")("Slider")),0,1);

fontName = weightSelect > 0 ? boldFonts[fontSelect] : fonts[fontSelect];
style.setFont(fontName)