// Isosceles_PrecompAllSelectedComps.jsx
// Code generated by ChatGPT-5.3
// Date: March 12, 2026
// Description: This script will precomp all layers into a single precomp. This will be applied to the selected comps in the Project window. This differs from the built-in way to do this in After Effects, since this technique is entirely automated.

{
    app.beginUndoGroup("Precompose Selected Comps");

    var project = app.project;
    var selection = project.selection;

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

        for (var i = 0; i < selection.length; i++) {

            var item = selection[i];

            if (item instanceof CompItem) {

                var comp = item;
                var numLayers = comp.numLayers;

                if (numLayers === 0) continue;

                var layerIndices = [];

                for (var j = 1; j <= numLayers; j++) {
                    layerIndices.push(j);
                }

                var newName = comp.name + "_PRECOMP";

                comp.layers.precompose(
                    layerIndices,
                    newName,
                    true // move all attributes
                );

            }

        }
    }

    app.endUndoGroup();
}