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

Issue with Collecting Keyframe Text in After Effects Script

New Here ,
Jun 28, 2024 Jun 28, 2024

Copy link to clipboard

Copied

Hello Everyone,

 

I'm new to After Effects scripting with JavaScript.

 

I've written a script to collect text layer properties (inTime, outTime, fontName, fontSize). Additionally, if the layer has keyframes, I need to gather the keyTime and text from those keyframes. While the script correctly collects the text properties, it doesn't accurately retrieve the text for each keyframe, instead, it returns the same text (from the first keyframe) for all keyframes.

 

Could anyone help me resolve this issue? Below is the script I've written.

 

Thank you!

getTextLayerInfo();

function getTextLayerInfo() {
	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 && myLayer.enabled) {
            var myTxtProps = myLayer.property("Text");
    
            for (var j = 1; j <= myTxtProps.numProperties; j++) {
                var myTxtProp = myTxtProps.property(j);
        
                if (myTxtProp.matchName === "ADBE Text Document") {
                    var myTxtDoc = myTxtProp.value;
                    var myCopy = myTxtDoc.text.replace("\r", " ", "gi");
                    var myStrtTme = timeToCurrentFormat(myLayer.inPoint, myComp.frameRate);
                    var myEndTme = timeToCurrentFormat(myLayer.outPoint, myComp.frameRate);
                    var myFntNm = myTxtDoc.fontFamily;
                    var myFntSz = myTxtDoc.fontSize;
        
                    var textInfo = {
                        text: myCopy,
                        inTime: myStrtTme,
                        outTime: myEndTme,
                        fontName: myFntNm,
                        fontSize: myFntSz,
                        keyframes: []
                    };
        
                    // Check for keyframes on the "Source Text" property
                    var sourceTextProp = myLayer.property("Source Text");
                    if (sourceTextProp.numKeys > 0) {
                        for (var k = 1; k <= sourceTextProp.numKeys; k++) {
                            var keyTime = timeToCurrentFormat(sourceTextProp.keyTime(k), myComp.frameRate);
                            var keyValue = sourceTextProp.keyValue(k).text.replace("\r", " ", "gi");
                            textInfo.keyframes.push({ time: keyTime, text: keyValue });
                        }
                    }
        
                    myTxtInfo_Ary.push(textInfo);
                }
            }
        }
	}
  
	for (var i = 0; i < myTxtInfo_Ary.length; i++) {
	  $.writeln("Text: " + myTxtInfo_Ary[i].text);
	  $.writeln("In Time: " + myTxtInfo_Ary[i].inTime);
	  $.writeln("Out Time: " + myTxtInfo_Ary[i].outTime);
	  $.writeln("Font Name: " + myTxtInfo_Ary[i].fontName);
	  $.writeln("Font Size: " + myTxtInfo_Ary[i].fontSize);
  
    if (myTxtInfo_Ary[i].keyframes.length > 0) {
        $.writeln("Keyframes:");
        
        for (var j = 0; j < myTxtInfo_Ary[i].keyframes.length; j++) {
            $.writeln("- Time: " + myTxtInfo_Ary[i].keyframes[j].time + ", Text: " + myTxtInfo_Ary[i].keyframes[j].text);
        }
    }
  
	  $.writeln("------");
	}
}

 

 

TOPICS
Scripting

Views

89

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
no replies

Have something to add?

Join the conversation