Page 1 of 1

Change Font and Font Style by script

Posted: March 20th, 2017, 5:25 am
by adayres
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:

Code: Select all

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  :(  

Code: Select all

textDocument.fontStyle = "Bold";
Does a magic trick exist?
Or maybe simply another way to do this?
Thanks by advance,
Aurélien

Re: Change Font and Font Style by script

Posted: March 20th, 2017, 1:57 pm
by zlovatt
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.

Code: Select all

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);

Re: Change Font and Font Style by script

Posted: March 19th, 2020, 10:31 am
by robthecramer
adayres wrote: March 20th, 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:

Code: Select all

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

This code is almost perfect for what I'm looking for! I want to be able to select all of my text layers, and change their font to the same font. This code only works on the top layer. I'm such a beginner with writing scripts and I'm having a tough time navigating the Adobe Scripting guide so I don't know exactly what to even search for. Any help would be amazing!


Re: Change Font and Font Style by script

Posted: September 29th, 2020, 11:02 am
by dave modis

There is an existing script for Changing the fonts in a project.
It does that and a lot more
FontMate:
https://www.vdodna.com/products/fontmate/


Re: Change Font and Font Style by script

Posted: October 5th, 2020, 10:55 am
by zlovatt
dave modis wrote: September 29th, 2020, 11:02 am

There is an existing script for Changing the fonts in a project.
It does that and a lot more
FontMate:
https://www.vdodna.com/products/fontmate/

Speaking of existing scripts, pt_textedit has been doing this since 2010 :wink: