Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Automating replacing source in sequences using sequences from another folder

  • Automating replacing source in sequences using sequences from another folder

    Posted by Jeremy Clevenger on January 15, 2024 at 2:32 am

    I am in the process of trying to write a script that will automate a very tedious process, but I have hit a wall. Essentially, I have two folders with identical amount of sequences with identical names. I want the script to replace layer 8 within the first sequence of the folder titled “names”, with the first item (a sequence) in the folder titled “photos” and iterate through all of the sequences doing this same process. I have written scripts that can iterate through items within a folder, but I am have issues with how After Effects defines and searches through multiple folders. Any thoughts on how to achieve this?

    Jeremy Clevenger replied 2 years, 6 months ago 1 Member · 1 Reply
  • 1 Reply
  • Jeremy Clevenger

    January 15, 2024 at 3:15 am

    For anyone trying to do a similar process… This is very specific to my project, but I got it to work.

    // Get the first folder in the root of the project

    var rootFolder = app.project.rootFolder.items[1];

    // Assume you have two folders inside the root folder

    var firstFolder = rootFolder.items[1];

    var secondFolder = rootFolder.items[2];

    // Check if the folders are valid

    if (firstFolder instanceof FolderItem && secondFolder instanceof FolderItem) {

    // Get the sequences in the second folder

    var sequencesInSecondFolder = secondFolder.items;

    // Iterate through sequences in the first folder

    var sequencesInFirstFolder = firstFolder.items;

    for (var i = 1; i <= sequencesInFirstFolder.length; i++) {

    var currentSequenceInFirstFolder = sequencesInFirstFolder[i];

    // Check if the current sequence is valid

    if (currentSequenceInFirstFolder instanceof CompItem) {

    // Open the current sequence in the viewer

    currentSequenceInFirstFolder.openInViewer();

    // Get the corresponding sequence in the second folder

    var correspondingSequenceInSecondFolder = sequencesInSecondFolder[i];

    // Check if the corresponding sequence is valid

    if (correspondingSequenceInSecondFolder instanceof CompItem) {

    // Replace layer 8 with the corresponding sequence

    var layerToReplaceIndex = 8; // Adjust index if needed

    var layerToReplace = currentSequenceInFirstFolder.layer(layerToReplaceIndex);

    if (layerToReplace) {

    layerToReplace.replaceSource(correspondingSequenceInSecondFolder, false);

    } else {

    alert(“Layer 8 not found in the current sequence.”);

    }

    } else {

    alert(“No valid corresponding sequence found in the second folder for the current sequence in the first folder.”);

    }

    } else {

    alert(“No valid sequence found in the first folder at index ” + i);

    }

    }

    } else {

    alert(“Invalid folder structure in the project.”);

    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy