-
Can’t add a file to timeline via scripting
Hello guys, i’m trying to add a file (mp3) wich i have imported in the after effects items panel. I want the button to add a specific file to the timeline in the current time, but everytime i click the button it says that the file is not imported in the project (but it is). Can you guys help me? Wha am i doing wrong? Here is the code:
function addFileToTimeline(fileName) {
var comp = app.project.activeItem; // Get the active composition
if (!comp || !(comp instanceof CompItem)) {
alert("Please select a composition in the project.");
return;
}
var importedFile = null;
// Loop through all items in the project to find the file by name
for (var i = 1; i <= app.project.items.length; i++) {
var item = app.project.items[i];
if (item.name.indexOf(fileName) !== -1 && item instanceof FootageItem) {
importedFile = item;
break;
}
}
if (!importedFile) {
alert("The file '" + fileName + "' is not imported in the project.");
return;
}
var layer = comp.layers.add(importedFile);
layer.startTime = comp.time; // Set the start time of the layer to the current time
}
// When the "Add Woosh to Timeline" button is clicked
panelOneButton1.onClick = function() {
addFileToTimeline("Woosh.mp3");
};