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.”);
}