// ISO_RemoveEffectFromSelectedLayers.jsx
// Artist: https://www.jasonfletcher.info/
// Code generated by ChatGPT-5.5 Mini
// Date: July 21, 2026
// Description: This After Effects script will remove all instances of a user-specified effect from the selected layers in the active composition.

(function () {
    app.beginUndoGroup("Remove Effect From Selected Layers");

    var processedLayers = 0;
    var effectsRemoved = 0;
    var skippedLockedLayers = [];
    var layersWithoutEffect = 0;
    var invalidLayers = 0;

    try {

        var comp = app.project.activeItem;

        if (comp === null || !(comp instanceof CompItem)) {
            alert("Please open a composition and select layers before running this script.");
            return;
        }

        if (comp.selectedLayers.length === 0) {
            alert("No layers are selected. Please select one or more layers in the composition timeline.");
            return;
        }

        var effectName = prompt("Enter the exact Display Name of the effect to remove:", "");

        if (effectName === null || effectName === "") {
            alert("No effect name was entered. Operation cancelled.");
            return;
        }

        var selectedLayers = comp.selectedLayers;

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

            var layer = selectedLayers[i];

            if (layer !== null) {

                if (layer.locked === true) {
                    skippedLockedLayers.push(layer.name);
                    continue;
                }

                processedLayers++;

                var effects = null;

                if (layer.property("ADBE Effect Parade") !== null) {
                    effects = layer.property("ADBE Effect Parade");
                }

                if (effects !== null) {

                    var layerHadEffect = false;

                    for (var e = effects.numProperties; e >= 1; e--) {

                        var effect = effects.property(e);

                        if (effect !== null) {

                            if (effect.name.toLowerCase() === effectName.toLowerCase()) {
                                effect.remove();
                                effectsRemoved++;
                                layerHadEffect = true;
                            }
                        }
                    }

                    if (layerHadEffect === false) {
                        layersWithoutEffect++;
                    }

                } else {
                    invalidLayers++;
                }

            } else {
                invalidLayers++;
            }
        }

        var report = "Operation Complete.\n\n";
        report += "Effect removed: " + effectName + "\n";
        report += "Layers processed: " + processedLayers + "\n";
        report += "Effects removed: " + effectsRemoved + "\n";
        report += "Layers without matching effect: " + layersWithoutEffect + "\n";
        report += "Layers without effect support: " + invalidLayers + "\n";

        if (skippedLockedLayers.length > 0) {
            report += "\nLocked layers skipped (" + skippedLockedLayers.length + "):\n";

            for (var s = 0; s < skippedLockedLayers.length; s++) {
                report += "- " + skippedLockedLayers[s] + "\n";
            }
        }

        alert(report);

    } catch (err) {

        alert("An error occurred:\n\n" + err.toString());

    } finally {

        app.endUndoGroup();

    }

})();