Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Generate Markers from text file

  • Generate Markers from text file

    Posted by Robin Kumar on January 13, 2019 at 10:04 am

    Hello!

    I need your help! I want to generate Markers on a selected layer based on absolute frame numbers from a given text file. Text file has frame numbers like this-

    These are absolute frame numbers. I am looking for following workflow-
    1)Select a layer
    2)Run the script
    3)It should prompt for text file
    4)After loading a text file, the script should generate Markers on a respective frames given on frame numbers in text file. Currently I am not looking to generate Marker comments. Just the Markers.

    Thank a lot! Any help is appreciated!! 🙂

    Robin Kumar replied 7 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    January 14, 2019 at 9:37 am

    You should save all those frame numbers in an array.
    then, to put markers on the layer use this
    var myMarker = new MarkerValue("Insert Comment Here");//leave blank for empty
    var frameDuration = app.project.activeItem.frameDuration;
    var timeArray = framesToTime(framesArray);//framesArray must be an array with the numbers from your file

    for (var i=0; i < timeArray.length; i++){
    myLayer.property("Marker").setValueAtTime(timeArray[i], myMarker);
    }

    function framesToTime(framesArray){
    var timeArray =[];
    for (var i=0; i < framesArray.length; i++){
    timeArray.push(framesArray[i]*frameDuration);
    }
    return timeArray;
    }

    Andrei
    My Envato portfolio.

  • Robin Kumar

    January 15, 2019 at 1:44 am

    Hey Andrei !

    Thanks for the reply, I tried your expression, its giving me a error that “myLayer is undefined”
    Am I doing something wrong? ☹

    Regards.

  • Andrei Popa

    January 18, 2019 at 7:08 am

    This should work. Select the layer you want to use the script on and then run it

    var myMarker = new MarkerValue("Insert Comment Here");//leave blank for empty
    var frameDuration = app.project.activeItem.frameDuration;
    var myFile = File.openDialog("Please select your marker file");
    var framesArray = extractDataFromFile(myFile);
    var timeArray = (framesArray!=null) ? framesToTime(framesArray) : [];//framesArray must be an array with the numbers from your file
    var myLayer = app.project.activeItem.selectedLayers[0];

    for (var i=0; i < timeArray.length; i++){
    myLayer.property("Marker").setValueAtTime(timeArray[i], myMarker);
    }

    function framesToTime(framesArray){
    var timeArray =[];
    for (var i=0; i < framesArray.length; i++){
    timeArray.push(framesArray[i]*frameDuration);
    }
    return timeArray;
    }

    function extractDataFromFile(myFile){
    if (!myFile) return;
    markerData = [];
    if (myFile.open("r")){
    while(!myFile.eof){
    var frameNumber = parseFloat(myFile.readln());
    markerData.push(frameNumber);
    }
    return markerData;
    }else alert("Could not open your file");
    }

    Andrei
    My Envato portfolio.

  • Robin Kumar

    January 25, 2019 at 2:33 am

    Thank you so much Andrei! It worked as expected!

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