// ISO_WorkAreaEndExtendByNFrames
// Artist: https://www.jasonfletcher.info/
// Code generated by ChatGPT-4o
// Date: April 16, 2025
// Description: This After Effects script extends the "Work Area End" point by a user-defined number of frames for selected comps in the Project window.

(function extendCompDurationByFrames() {
    var selectedItems = app.project.selection;

    if (selectedItems.length === 0) {
        alert("Please select one or more compositions in the Project panel.");
        return;
    }

    // Ask the user how many frames to add
    var input = prompt("Enter the number of frames to extend the comps by:", "60");
    if (input === null) return; // User cancelled
    var framesToAdd = parseInt(input, 10);

    if (isNaN(framesToAdd)) {
        alert("Please enter a valid number.");
        return;
    }

    var processedComps = 0;

    app.beginUndoGroup("Extend Comp Duration by " + framesToAdd + " Frames");

    for (var i = 0; i < selectedItems.length; i++) {
        var item = selectedItems[i];

        if (item instanceof CompItem) {
            var originalDuration = item.duration;
            var frameRate = item.frameRate;
            var addedTime = framesToAdd / frameRate;
            item.duration = originalDuration + addedTime;

            processedComps++;
        }
    }

    app.endUndoGroup();

    alert(
        "Comps processed: " + processedComps + "\n" +
        "Frames extended per comp: " + framesToAdd
    );
})();