// ISO_RemoveExpressions.jsx
// Artist: https://www.jasonfletcher.info/
// Code generated by ChatGPT-4o
// Date: June 9, 2026
// Description: This After Effects script removes all expressions from all layers. This operation will be executed for the selected comps in the Project window.

(function removeExpressionsFromSelectedComps() {

    var items = app.project.selection;

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

    var compsProcessed = 0;
    var layersTouched = 0;
    var expressionsRemoved = 0;

    app.beginUndoGroup("Remove Expressions from Selected Comps");

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

        if (!(item instanceof CompItem)) {
            continue;
        }

        compsProcessed++;
        var comp = item;

        for (var l = 1; l <= comp.numLayers; l++) {
            var layer = comp.layer(l);
            var layerHadExpression = false;

            if (!layer) continue;

            var beforeCount = expressionsRemoved;

            removeExpressionsRecursively(layer);

            if (expressionsRemoved > beforeCount) {
                layerHadExpression = true;
            }

            if (layerHadExpression) {
                layersTouched++;
            }
        }
    }

    app.endUndoGroup();

    alert(
        "Comps processed: " + compsProcessed + "\n" +
        "Layers affected: " + layersTouched + "\n" +
        "Expressions removed: " + expressionsRemoved
    );

    function removeExpressionsRecursively(group) {
        var numProps = group.numProperties;

        for (var i = 1; i <= numProps; i++) {
            var prop = group.property(i);

            if (!prop) continue;

            // If property has expression, remove it
            if (prop.canSetExpression && prop.expressionEnabled) {
                prop.expression = "";
                prop.expressionEnabled = false;
                expressionsRemoved++;
            }

            // Recurse into property groups
            if (prop.propertyType === PropertyType.PROPERTY_GROUP ||
                prop.propertyType === PropertyType.NAMED_GROUP) {
                removeExpressionsRecursively(prop);
            }
        }
    }

})();