redefinery

Footage

This section describes how to work with footage items in the project (Project panel). The following topics are covered:


Retrieving all footage items in the project

The Project panel contains various types of items, such as compositions, footage, and folders. Footage items are represented as FootageItem objects, which are subclassed (and consist of attributes and methods of) Item objects.

The following code shows how to retrieve all footage items in the project and store them in an array for retrieval or use elsewhere in your code.

// given:
// app = Application object representing After Effects
// app.project = Project object representing the current project
//
var items = app.project.items;
var allFootage = new Array();                    // Store footage items in an array

for (var i = 1; i <= items.length; i++)
    if (items[i].typeName === "Footage")         // Retrieve only footage items
        allFootage[allFootage.length] = items[i];

// The allFootage array now contains the list of footage items
// The number of footage items is allFootage.length

Retrieving the selected footage items in the project

If your script needs to operate on the selected footage items in the project, you can either check the selected items (in app.project.selection) for footage items, or check all items (in app.project.items) for selected footage.
Personally, I prefer the first of these options as the script does not need to iterate over unselected items.

Note: There does not seem to be a way to retrieve the selected footage items (or any type of selected item) in selected order.

The following code shows how to iterate over the selected items, and store only footage items in an array for retrieval or use elsewhere in your code.

// given:
// app = Application object representing After Effects
// app.project = Project object representing the current project
//
var selectedItems = app.project.selection;        // Start with the selected items
var selectedFootage = new Array();                // Store footage items in an array

for (var i = 0; i < selectedItems.length; i++)
    if (selectedItems[i].typeName === "Footage")
        selectedFootage[selectedFootage.length] = selectedItems[i];

// The selectedFootage array now contains the list of selected footage items
// The number of selected footage items is selectedFootage.length in top-to-bottom order

Checking if the selected footage item is an image sequence

If your script needs to determine if a selected footage item is an image sequence, you'll want to check that the footage item is not a still image but if the item's source file is imported it is a still image. You can use this technique to determine if a layer's source is an image sequence, too. Thanks to Keiko from the After Effects team for assistance.

The following code shows how to check if the active item is an image sequence.

// given:
// app = Application object representing After Effects
// app.project = Project object representing the current project
//
var activeItem = app.project.activeItem;          // Start with the active/selected item
var isSequence = false;                           // Assume it isn't an image sequence

if (activeItem && activeItem instanceof FootageItem)
{
    if (activeItem.mainSource instanceof FileSource)
    {
        if (!activeItem.mainSource.isStill)
        {
            // Do a test import to see if the file is a still image
            try
            {
                var tempIO = new ImportOptions( activeItem.mainSource.file );
                tempIO.importAs = ImportAsType.FOOTAGE;
                var tempFI = app.project.importFile(tempIO);
                
                isSequence = tempFI.mainSource.isStill;
                
                tempFI.remove();
            }
            catch (e)
            {
                alert("ERROR: cannot import file " + activeItem.item(1).mainSource.file.fsName + " - " + e.toString());
            }
        }
    }
}

// The isSequence value will be true if the selected item is an image sequence