Copy link to clipboard
Copied
What command to add video to After Effects?
For example, the file "C:/Users/jamesc/video.mp4" needs to be added into my AE.
How do I add it in as a resource and then put it into the composition?
1 Correct answer
Here you go.
The following function will import your footage and add it to an opened composition.
...var file = "C:/Users/jamesc/video.mp4";
function importFootage(file) {
var myComp = app.project.activeItem; // your opened composition
if (!myComp || !(myComp instanceof CompItem)) {
alert("Please, open composition");
return false;
}
app.beginUndoGroup("Import file");
var importOpts = new ImportOptions(File(file));
var importFootage = app.project.importFile(importOpts);
Copy link to clipboard
Copied
Here you go.
The following function will import your footage and add it to an opened composition.
var file = "C:/Users/jamesc/video.mp4";
function importFootage(file) {
var myComp = app.project.activeItem; // your opened composition
if (!myComp || !(myComp instanceof CompItem)) {
alert("Please, open composition");
return false;
}
app.beginUndoGroup("Import file");
var importOpts = new ImportOptions(File(file));
var importFootage = app.project.importFile(importOpts);
var myFootage = myComp.layers.add(importFootage); // add footage to your composition
app.endUndoGroup();
};
Copy link to clipboard
Copied
I think you can fetch the composition like this if you do not want to work with the currently active one:
/**
* Returns e.g. a composition from the bins.
* If there are more files with the same name,
* the first one will be returned and others will be ignored.
* @param string name The name of the item to retrieve
*/
getFolderItemByName: function getFolderItemByName(name) {
var project = app.project;
for (var index = 1; index <= project.numItems; index++) {
var folderItem = project.item(index);
if (folderItem && folderItem.name === name) {
return folderItem;
}
}
return null;
},
Or if you want to bring a composition to the active state, you can set it:
composition.selected = true;

