Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Convert Text Source Keyframes to Marker layers with same text

  • Convert Text Source Keyframes to Marker layers with same text

  • Craig Trayler

    March 7, 2022 at 4:20 pm

    Hi CC, I have a very long project that on top layer has a single text layer that contains 100’s of Source text keyframes (used for subtitles).

    I am looking for a way/script that would take the selected text layer in the active comp, add a marker point on the same frame as the source text keyframe, and then copy the text in that keyframe and paste it into each marker comment.

    I have seen some code to create markers based on keyframes, but nothing about pulling text data from source text keyframes any adding to marker comments. I love to learn but this has stumped me.

    Thanks again for any help on this one.
    – Craig

  • Dan Ebberts

    March 7, 2022 at 5:25 pm

    This should get you close:

    function keyframesToMarkers(){

    var myComp = app.project.activeItem;

    if (myComp == null || ! (myComp instanceof CompItem)){

    alert ("No comp active.");

    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 a text layer.");

    return;

    }

    var markerVal = new MarkerValue("");

    var mySourceText = myLayer.property("ADBE Text Properties").property("ADBE Text Document");

    var myTextDoc;

    for (var i = 1; i <= mySourceText.numKeys; i ++){

    myTextDoc = mySourceText.keyValue(i);

    markerVal.comment = myTextDoc.text;

    myLayer.property("Marker").setValueAtTime(mySourceText.keyTime(i),markerVal);

    }

    }

    keyframesToMarkers();

  • Craig Trayler

    March 7, 2022 at 5:54 pm

    Thank you Dan! Your works are just great. This worked perfectly.
    One more thing if I may, I have only just noticed some Source text keyframes were purposely made empty/Blank/containing not text, is there a line of code you can add to check that if the Keyframe is empty, to ignore making a marker and move onto the next one?

  • Dan Ebberts

    March 7, 2022 at 6:52 pm

    Just put this line:

    if (myTextDoc.text == "") continue;

    right before this one:

    markerVal.comment = myTextDoc.text;

  • Craig Trayler

    March 8, 2022 at 9:41 am

    Fantastic, thank you again Dan.

  • Craig Trayler

    June 13, 2022 at 11:23 am

    Hi Dan or anyone who can assist a little more.
    Everything is great, but wanted to know if there is also a way to add duration of each created marker to extend it’s length until the next following text source keyframe?

    I would venture a guess that there needs to be an If function to check if there is a next keyframe to counter an error for the very last keyframe.

    Thanks in advance,
    Craig

  • Dan Ebberts

    June 13, 2022 at 2:19 pm

    Like this, I guess:

    function keyframesToMarkers(){

    var myComp = app.project.activeItem;

    if (myComp == null || ! (myComp instanceof CompItem)){

    alert ("No comp active.");

    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 a text layer.");

    return;

    }

    var markerVal = new MarkerValue("");

    var mySourceText = myLayer.property("ADBE Text Properties").property("ADBE Text Document");

    var myTextDoc;

    for (var i = 1; i <= mySourceText.numKeys; i ++){

    myTextDoc = mySourceText.keyValue(i);

    if (myTextDoc.text == "") continue;

    markerVal.comment = myTextDoc.text;

    if (i < mySourceText.numKeys){

    markerVal.duration = mySourceText.keyTime(i+1) - mySourceText.keyTime(i);

    }else{

    markerVal.duration = 0;

    }

    myLayer.property("Marker").setValueAtTime(mySourceText.keyTime(i),markerVal);

    }

    }

    keyframesToMarkers();

Viewing 1 - 7 of 7 posts

Log in to reply.

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