Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Selecting Empty Source text Keyframe through Expression

  • Selecting Empty Source text Keyframe through Expression

    Posted by Johanna Peterson on September 18, 2012 at 9:25 pm

    Hello!

    I’m doing some subtitles and I used a script I found online but the problem is I still need to select all Empty Source Text Keyframes that the script had created the entire subtitles. How do you select these Empty Source Text Keyframes all at once through a script? Its hard to select them manually through each line. I hope somebody could help me find a script to select these so I can just delete them. Thanks for your help!

    Johanna Peterson replied 13 years, 10 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    September 19, 2012 at 2:57 am

    By empty keyframes, do you mean keyframes where there is no text? If so, something like this should remove those keyframes from the selected text layer:


    {
    function main(){
    var myComp = app.project.activeItem;
    if ((myComp == null) || ! (myComp instanceof CompItem)){
    alert("No comp selected.");
    return;
    }
    if (myComp.selectedLayers.length == 0){
    alert("No layer selected.");
    return;
    }
    var myLayer = myComp.selectedLayers[0];
    if (!(myLayer instanceof TextLayer)){
    alert("Selected layer is not text layer");
    return;
    }
    var myProp = myLayer.property("Text").property("Source Text");
    for (var i = myProp.numKeys; i > 0; i--){
    if (myProp.keyValue(i) == ""){
    myProp.removeKey(i);
    }
    }
    }
    main();
    }

    Dan

  • Johanna Peterson

    September 19, 2012 at 3:16 pm

    Hi Dan,

    Thank you for your response! You’re right Empty text meaning No Text. I’m not really good at scripting and I might be doing it incorrectly. When I tried saving the code into .jsx and run the script with the selected text layer, it didn’t work for me. I’m using AE CS5 in Mac, i’m uncertain if there should be added/changed values in the script to work on Mac or if there are other things I need to do.

    This is how I hope it would happen so then I can just delete them all at once.

    I appreiate your help. Thanks!

    Johanna

  • Johanna Peterson

    September 19, 2012 at 3:52 pm

    I probably had a mistake on identifying what’s on the Text Layer. It looks like its empty but when I selected that keyframe it had that “blank space” or ” ” in that keyframes. Can you help me on the script modifications?

    Screenshot on the keyframe to delete:

    spaceintext-keyframesnotemptytext.png

    Thank you !

  • Johanna Peterson

    September 19, 2012 at 4:16 pm

    Oh yeah I think I had a lucky guess on the changes on the script. It worked for me 🙂

    here is how I’ve tried changing them:

    {
    function main(){
    var myComp = app.project.activeItem;
    if ((myComp == null) || ! (myComp instanceof CompItem)){
    alert("No comp selected.");
    return;
    }
    if (myComp.selectedLayers.length == 0){
    alert("No layer selected.");
    return;
    }
    var myLayer = myComp.selectedLayers[0];
    if (!(myLayer instanceof TextLayer)){
    alert("Selected layer is not text layer");
    return;
    }
    var myProp = myLayer.property("Text").property("Source Text");
    for (var i = myProp.numKeys; i > 1; i--){
    if (myProp.keyValue(i) == " "){
    myProp.removeKey(i);
    }
    }
    }
    main();
    }

    Thanks Dan for the script~! 🙂

    For my last question, how do you modify the script if I wanted to select multiple text layers in the composition and delete these keyframes with space in text layers? THANKS!

  • Dan Ebberts

    September 19, 2012 at 5:44 pm

    You just need to loop through the selected layers:


    {
    function main(){
    var myComp = app.project.activeItem;
    if ((myComp == null) || ! (myComp instanceof CompItem)){
    alert("No comp selected.");
    return;
    }
    if (myComp.selectedLayers.length == 0){
    alert("No layer selected.");
    return;
    }
    for (var j = 0; j < myComp.selectedLayers.length; j++){
    var myLayer = myComp.selectedLayers[j];
    if (!(myLayer instanceof TextLayer)){
    alert("Selected layer is not text layer");
    return;
    }
    var myProp = myLayer.property("Text").property("Source Text");
    for (var i = myProp.numKeys; i > 1; i--){
    if (myProp.keyValue(i) == " "){
    myProp.removeKey(i);
    }
    }
    }
    }
    main();
    }

    Dan

  • Johanna Peterson

    September 19, 2012 at 6:32 pm

    Thank you so much Dan!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy