• 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

119

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 ,
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

LATEST

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