Select all text layers (also in sub comps) and change color with script in After Effects

79 views Asked by At

I was able to change the color of all the text layers in a comp but I can't find a way to do it also on text layers in sub-comps. There is any way to select all the text layer including sub-comps? Thanks

var dialog = new Window("dialog", "Select Color");
dialog.orientation = "column";

var group = dialog.add("group");
group.orientation = "row";
var buttonWhite = group.add("button", undefined, "White");
buttonWhite.onClick = function() {
    setColorText([1, 1, 1]); // Set color to white (RGB: 1,1,1)
    dialog.close();
};
var buttonBlack = group.add("button", undefined, "Black");
buttonBlack.onClick = function() {
    setColorText([0, 0, 0]); // Set color to black (RGB: 0,0,0)
    dialog.close();
};

dialog.show();

function setColorText(color) {
    var comp = app.project.activeItem;
    if (comp && comp instanceof CompItem) {
        for (var j = 1; j <= comp.layers.length; j++) {
            comp.layers[j].selected = false;
        }
        for (var k = 1; k <= comp.layers.length; k++) {
            var currentLayer = comp.layers[k];
            selectTextAndSetColor(currentLayer, color);
        }
    }
}

function selectTextAndSetColor(layer, color) {
    if (layer instanceof TextLayer) {
        layer.selected = true;
        var textProp = layer.property("Source Text");
        if (textProp) {
            var textDocument = textProp.value;
            textDocument.fillColor = color;
            textProp.setValue(textDocument);
        }
    }
    if (layer instanceof CompItem) {
        for (var i = 1; i <= layer.layers.length; i++) {
            selectTextAndSetColor(layer.layers[i], color);
        }
    }
}

0

There are 0 answers