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

Select Font Family and Font Weight with script

Community Beginner ,
Mar 23, 2023 Mar 23, 2023

Copy link to clipboard

Copied

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?

TOPICS
Expressions , How to , Scripting

Views

238

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

correct answers 1 Correct answer

Community Expert , Apr 03, 2023 Apr 03, 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
...

Votes

Translate

Translate
Community Beginner ,
Apr 03, 2023 Apr 03, 2023

Copy link to clipboard

Copied

Anyone can help me? Please!

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 ,
Apr 03, 2023 Apr 03, 2023

Copy link to clipboard

Copied

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)

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
Adobe Employee ,
Nov 20, 2023 Nov 20, 2023

Copy link to clipboard

Copied

LATEST

@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

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