Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
adayres
Topic Author
Posts: 1
Joined: Wed Mar 26, 2014 3:29 am

Change Font and Font Style by script

Mon Mar 20, 2017 5:25 am

Hello,

For a client, I have to change the Font of  text layer with a script.
I manage to change the Font itself like this:

var textProp =    app.project.activeItem.layer(1).property("Source Text");
      var textDocument = textProp.value;
      textDocument.font = "Arial";
textProp.setValue(textDocument);



But unfortunately I don't manage to change the style
With the line below, After Effects return fontSyle is in ReadOnly  :(  

textDocument.fontStyle = "Bold";


Does a magic trick exist?
Or maybe simply another way to do this?
Thanks by advance,
Aurélien
 
User avatar
zlovatt
Posts: 12
Joined: Mon Oct 31, 2016 5:00 pm
Location: Los Angeles
Contact:

Re: Change Font and Font Style by script

Mon Mar 20, 2017 1:57 pm

Via Tomas Sinkunas, these are all the script-accessible text properties.

It looks like you'll need to set the font to "Arial-Bold" and that could work.

var textLayer = comp1_comp.layers.addText("This is BOLD");
var textLayer_TextProp = textLayer.property("ADBE Text Properties").property("ADBE Text Document");
var textLayer_TextDocument = textLayer_TextProp.value;
textLayer_TextDocument.font = "Arial-BoldMT";
textLayer_TextDocument.fontSize = 36;
textLayer_TextDocument.applyFill = true;
textLayer_TextDocument.fillColor = [0.29019600152969, 0.6941180229187, 0.835294008255];
textLayer_TextDocument.applyStroke = false;
textLayer_TextDocument.justification = ParagraphJustification.CENTER_JUSTIFY;
textLayer_TextDocument.tracking = 30;
if (parseFloat(app.version) >= 13.2) {
   textLayer_TextDocument.verticalScale = 1;
   textLayer_TextDocument.horizontalScale = 1;
   textLayer_TextDocument.baselineShift = 0;
   textLayer_TextDocument.tsume = 0;
   // These values are read-only. You have to set them manually in the comp.
   // textLayer_TextDocument.fauxBold = false;
   // textLayer_TextDocument.fauxItalic = false;
   // textLayer_TextDocument.allCaps = false;
   // textLayer_TextDocument.smallCaps = false;
   // textLayer_TextDocument.superscript = false;
   // textLayer_TextDocument.subscript = false;
}
textLayer_TextProp.setValue(textLayer_TextDocument);

Who is online

Users browsing this forum: No registered users and 1 guest