Skip to main content
Known Participant
June 11, 2024
Answered

How to get the mixed up character properties (font size and font style) from the same text layer

  • June 11, 2024
  • 1 reply
  • 628 views

Hi All, 

I need a script to find out, if the text layer contain more than one font style or font size (different font style or font size used in the same layer) in After effects.

I have the script (placed below) for get the font style, font size details in the after effects, but it will give the details for the first character's properties alone.

Can you please advise to get each word properties or else to alert if the text layer contain more than one format (either font or font size).

 

 

query();

function query() {
    var myTxtInfo_Ary = [];
	var myProj = app.project;
	var myComp = myProj.activeItem;
	var myLayers = myComp.layers;

    for (var i = 1; i <= myLayers.length; i++) {
        var myLayer = myLayers[i];
        if (myLayer instanceof TextLayer) { // Check if the layer is a text layer
			if (myLayer.enabled == true) { // Check if the layer is enabled
				var myTxtProp = myLayer.property("ADBE Text Properties").property("ADBE Text Document"); 
                var myTxtDoc = myTxtProp.value; // Access the text document

                var myCopy = myTxtDoc.text;
                var myFontStyle = myTxtDoc.fontStyle;
                var myFontSize = myTxtDoc.fontSize;

                // pushing text properties
                myTxtInfo_Ary.push({
                    text: myCopy,
                    fontStyle: myFontStyle,
                    fontSize: myFontSize
                });
            }
        }
    }

    for (var i = 0; i < myTxtInfo_Ary.length; i++) {
		$.writeln("Text: " + myTxtInfo_Ary[i].text);
		$.writeln("Font Style: " + myTxtInfo_Ary[i].fontStyle);
		$.writeln("Font Size: " + myTxtInfo_Ary[i].fontSize);
		$.writeln("------");
	}
}

 

 



Thanks
Asuvath

This topic has been closed for replies.
Correct answer Paul Tuersley

You can  do this in After Effects v24.3 and later by using the new CharacterRange object:

https://ae-scripting.docsforadobe.dev/text/characterrange.html

 

var textDocument = app.project.activeItem.layer(1).property("Source Text").value;
var characterRange = textDocument.characterRange(0,-1);
alert("mixed size = " + (characterRange.fontSize == undefined));
alert("mixed font = " + (characterRange.font == undefined));

 

 

1 reply

Paul TuersleyCorrect answer
Inspiring
June 11, 2024

You can  do this in After Effects v24.3 and later by using the new CharacterRange object:

https://ae-scripting.docsforadobe.dev/text/characterrange.html

 

var textDocument = app.project.activeItem.layer(1).property("Source Text").value;
var characterRange = textDocument.characterRange(0,-1);
alert("mixed size = " + (characterRange.fontSize == undefined));
alert("mixed font = " + (characterRange.font == undefined));

 

 

AsuvathAuthor
Known Participant
June 11, 2024

Hi @Paul Tuersley ,

Thank you, Sorry I donot have this version. I have the lower version 24.1.0.

Is there another way to achieve this with this version?

Thanks
Asuvath

Inspiring
June 11, 2024

No. It's not something we ever had the ability to do before this recent update.