Issue with Duplicate Clips When Inserting from Tabulated File in Adobe Premiere Pro Script
The script is designed to facilitate the process of inserting selected clips from an active sequence in Adobe Premiere Pro into a new sequence. Despite the intended functionality, I am experiencing an issue where clips are being duplicated in the new sequence. The insertion logic seems to be adding clips multiple times, which is not the desired behavior. I would like to understand why this duplication is occurring and how to resolve it.
// Function to create the new sequence from the tabulated file
function createSequenceFromFile(filePath, project, newSequence) {
$.writeln("Reading file information: " + filePath);
var file = new File(filePath);
if (!file.exists) {
$.writeln("File not found: " + filePath);
return;
}
file.open("r");
var line;
var newVideoTrack = newSequence.videoTracks[0];
var insertPosition = 0;
// Ignore the header
file.readln();
// Read each line of the file
while (!file.eof) {
line = file.readln();
var parts = line.split("\t");
if (parts.length === 4) {
var clipName = parts[0];
var inPoint = parseFloat(parts[1]);
var outPoint = parseFloat(parts[2]);
var duration = outPoint - inPoint;
$.writeln("Inserting clip: " + clipName + " at position: " + insertPosition);
var projectItem = findProjectItem(clipName); // Find the project item
if (projectItem) {
var newClip = newVideoTrack.insertClip(projectItem, insertPosition);
if (newClip) {
newClip.end = newClip.start + duration;
insertPosition += duration;
$.writeln("Clip successfully inserted: " + clipName);
} else {
$.writeln("Error inserting clip: " + clipName);
}
} else {
$.writeln("Clip not found in project: " + clipName);
}
}
}
file.close();
}
// Function to find the project item by name (recursive search)
function findProjectItem(clipName) {
return recursiveSearch(app.project.rootItem, clipName);
}
// Recursive function to search for the item
function recursiveSearch(folder, clipName) {
for (var i = 0; i < folder.children.numItems; i++) {
var item = folder.children[i];
if (item.name === clipName) {
return item; // Return the project item that matches the name
}
if (item.type === ProjectItemType.BIN) { // If it's a folder, search recursively
var found = recursiveSearch(item, clipName);
if (found) {
return found; // Return if found in subfolders
}
}
}
return null; // Return null if the item is not found
}
