ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Generate Markers from text file

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Robin Kumar
Generate Markers from text file
on Jan 13, 2019 at 10:04:29 am
Last Edited By Robin Kumar on Jan 13, 2019 at 10:05:13 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!! :-)


Return to posts index

Andrei Popa
Re: Generate Markers from text file
on Jan 14, 2019 at 9:37:56 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.


Return to posts index

Robin Kumar
Re: Generate Markers from text file
on Jan 15, 2019 at 1:44:54 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.


Return to posts index


Andrei Popa
Re: Generate Markers from text file
on Jan 18, 2019 at 7:08:31 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.


Return to posts index

Robin Kumar
Re: Generate Markers from text file
on Jan 25, 2019 at 2:33:24 am

Thank you so much Andrei! It worked as expected!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]