I have a script that imports a persons name via a text file (this part works fine) then I need to add an image also but this is not working.
The image location is inside the text file.
Error for image is: After Effect error: ~/Custom Images/myImg.jpg is Not a file or folder object
Text file contains:
Adam ~/Custom Images/myImg.jpg
John ~/Custom Images/myImg.jpg
Katie ~/Custom Images/myImg.jpg
My script file contains:
var newFile = File.openDialog("Choose file to read.");
if(newFile != null){
var a = readDocument(newFile, 0).contentAry;
app.beginUndoGroup("Import Text");
createNewComps(a);
app.endUndoGroup();
}
function readDocument(inputDoc, linesToSkip){
var curDoc = new File(inputDoc);
if (curDoc.exists){
var contentAry = new Array();
curDoc.open("r"); // r = read document
while(!curDoc.eof){
contentAry[contentAry.length] = curDoc.readln(); // Read in each line of information to the array
}
curDoc.close(); // Close the document
}
contentAry.splice(0, linesToSkip); // Removes content to skip
var contentList = contentAry.join("_dpt_").toString().replace(new RegExp("_dpt_","g"), "\r");
contentAry = contentAry;
return {
'contentAry': contentAry,
'contentList': contentList
}
}
function createNewComps(content){
try{
if(content instanceof Array){
var c, compName, curLine, line1, imgFile, pl;
var aryLength = content.length;
for(var i=0; i<aryLength; i++){
curLine = content[i];
pl = parse(curLine); // custom function
line1 = pl.firstName;
imgFile = pl.bgImage;
compName = "1. " + pl.firstName;
if(curLine != ""){
c = app.project.items.addComp(compName, 1920, 1080, 1.0, 10, 24); // width, height, pixal ratio, duration, framerate
createNameLayers(c, line1); // (assigned comp, text)
createImageLayers(c, imgFile);
}
}
}
}catch(err){alert(err.line.toString() + "\r" + err.toString())};
}
function parse(myText){
var t = myText.split("\t");
return{
'firstName': t[0],
'bgImage': t[1]
}
}
function createNameLayers(comp, myText){
var newTextLayer = comp.layers.addText("a");
newTextLayer.property("ADBE Transform Group").property("ADBE Position").setValue([comp.width*0.07, comp.height*0.41]);
var textProp = newTextLayer.property("Source Text");
var textDocument = textProp.value;
textDocument.resetCharStyle();
textDocument.fontSize = 147;
textDocument.fillColor = [0, 1, 0]; // RGB
textDocument.strokeColor = [0, 1, 0];
textDocument.strokeWidth = 0;
textDocument.font = "Frutiger Neue LT Com";
textDocument.strokeOverFill = false;
textDocument.applyStroke = false;
textDocument.applyFill = true;
textDocument.text = myText;
textDocument.justification = ParagraphJustification.LEFT_JUSTIFY;
textDocument.tracking = 50;
textProp.setValue(textDocument); // sets the above
}
// --- NOT WORKING FUNCTION --
function createImageLayers(comp, myText){
//var newImageLayer = comp.layers.add("a");
var io = new ImportOptions (myText);
//First you need to define an ImportOptions object:
var io = new ImportOptions();
//Then you set the file attribute to the file object you want to import:
io.file = myText;
//Then you can import it:
//var myFootage = app.project.importFile(io);
var myFootage = app.project.item(1).mainSource.file
}
Any help would be appreciated