Created
April 28, 2018 14:13
-
-
Save fk128/7a4978a2d6d38b75cb4f4a9d09f69272 to your computer and use it in GitHub Desktop.
insert text overlays at timestamps in after effects from text file input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Modified from: | |
SRT subtitle import for AE CS5 | |
By August Bering | |
*/ | |
/* | |
example text file input containing: | |
0:15 | |
hello | |
0:23 | |
world | |
0:35 | |
!!! | |
*/ | |
function makeSubs() { | |
function getframe(timeInString){ | |
var t=timeInString.split(":"); | |
var timeS=parseInt(t[0])*60+parseInt(t[1]); | |
var frame=timeS*25; | |
var duration = 3; // duration for text to show | |
return timeS; | |
} | |
var pb=progressBar("Creating keyframes",); | |
var layer = app.project.activeItem.selectedLayers[0]; | |
if (layer.property("sourceText") != null) { | |
var textFile = File.openDialog("Select a text file to open.", "text file:*.txt"); | |
if (textFile != null) { | |
var textLines = new Array(); | |
textFile.open("r", "TEXT", "????"); | |
var sourceText = layer.property("sourceText"); | |
var subnr=0; | |
var nrSubs=0; | |
while (!textFile.eof) { | |
if (""==textFile.readln()) | |
nrSubs++; | |
} | |
textFile.seek(0); | |
//begin with empty text | |
sourceText.setValueAtTime(0,""); | |
while (!textFile.eof) { | |
pb.setValue(subnr/nrSubs); | |
// $.sleep(1); | |
pb.p.update(); | |
if (pb.isCanceled ()){//for some reason this doesn't work at all, the window is unresponsive... | |
pb.close(); | |
return; | |
} | |
subnr++; | |
var line = textFile.readln(); | |
var times=line; | |
var starttime=getframe(times); | |
var stoptime=starttime+duration; | |
var text="" | |
while ((line= textFile.readln())!=""){ | |
text+=line+"\r\n"; | |
} | |
sourceText.setValueAtTime(starttime,text); | |
sourceText.setValueAtTime(stoptime,""); | |
} | |
textFile.close(); | |
pb.close(); | |
} | |
} | |
} | |
/* | |
Easy to use progress bar for ExtendScript. | |
Written by [email protected], 2007 | |
Enjoy, but this credit must remain intact. | |
>usage: | |
> var pb = progressBar("main title","subtitle"); | |
pb.setValue(valueFrom0to1); | |
pb.setTitle2("new subtitle display!") | |
if(pb.isCanceled()) | |
pb.close(); // they clicked cancel | |
*/ | |
function progressBar(title1) | |
{ | |
var result = new Object(); | |
result.running = true; | |
result.p = new Window("palette"); | |
result.p.orientation = "column"; | |
result.p.alignChildren = "left"; | |
result.t1 = result.p.add("statictext",undefined,title1); | |
result.b = result.p.add("progressbar"); | |
result.c = result.p.add("button",undefined,"Cancel"); | |
result.c.onClick = function() { | |
this.running = false; | |
} | |
result.isRunning = function() { return this.running; } | |
result.isCanceled = function() { return !this.isRunning(); } | |
result.setValue = function(x) { this.b.value = x * 100; } | |
result.setTitle1 = function(t1) { this.t1.text = t1; } | |
result.close = function() { this.p.close(); } | |
result.p.show(); | |
return result; | |
} | |
makeSubs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment