Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Enabling/Disabling Layers with Layer Name

  • Enabling/Disabling Layers with Layer Name

  • Addison Taylor

    May 18, 2020 at 4:45 pm

    Hi Everyone,

    Longtime lurker here and finally made an account. I’ve been helped out greatly in the past with expressions posted here by other users and will be forever grateful.

    I’m struggling to get a script to work which someone posted on here from 2016 and cannot find any other solutions so was hoping someone may be able to help! This script seems to search through all the layers and disable layers based on the last two digits of the layer name, it works for text layers but I’m wanting to get it to work on video footage just can’t seem to crack it. If there’s also a better way to do this based on the language that’d be awesome.

    Any help would be very much appreciated! 🙂

    function hideLayer (layer, selectedLanguage){
    // Hide/Show layers according to the last 2 digits of layer's name
    if (layer.hasVideo && selectedLanguage == "All" || == selectedLanguage){layer.enabled = true};
    else {layer.enabled = false};
    if (layer.hasAudio && selectedLanguage == "All" || == selectedLanguage){layer.audioEnabled = true};
    else {layer.audioEnabled = false};
    // For layers used both in EN & FR version
    if ( == "EN/FR" && selectedLanguage == "EN" && layer.hasVideo){layer.enabled = true};
    if ( == "EN/FR" && selectedLanguage == "EN" && layer.hasAudio){layer.audioEnabled = true};
    if ( == "EN/FR" && selectedLanguage == "CH" && layer.hasVideo){layer.enabled = false};
    if ( == "EN/FR" && selectedLanguage == "CH" && layer.hasAudio){layer.audioEnabled = false};
    // Scan all layers
    function goThroughLayers (Comp, selectedLanguage){
    for (var p = 1; p <= Comp.numLayers; p++){
    // Check if layer needs to be modified
    if(Comp.layer(p).name.slice(-2) == "EN" || Comp.layer(p).name.slice(-2) == "FR" || Comp.layer(p).name.slice(-2) == "CH"){
    hideLayer(Comp.layer(p), selectedLanguage);

    var w =new Window ("dialog","Select language");
    var radio_group = w.add ("panel");
    radio_group.alignChildren ="center";
    radio_group.add ("radiobutton", undefined, "EN");
    radio_group.add ("radiobutton", undefined, "FR");
    radio_group.add ("radiobutton", undefined, "CH");
    radio_group.add ("radiobutton", undefined, "All");
    var button_group = w.add ("group");
    button_group.alignChildren ="center";
    button_group.add ("button", undefined, "Cancel");
    button_group.add ("button", undefined, "OK");

    // set dialog defaults
    radio_group.children[0].value =true;

    if( ()== 1){
    // Get selected language
    for(var x = 0; x < radio_group.children.length; x++){
    if(radio_group.children[x].value ==true){var selectedLanguage = (radio_group.children[x].text)};

    app.beginUndoGroup("Language selection");

    // Search for all Compositions in the project
    for (var i = 1; i <= app.project.numItems; i++) {
    if (app.project.item(i) instanceof CompItem) {
    var Comp = app.project.item(i);
    goThroughLayers(Comp, selectedLanguage);

  • Andrei Popa

    May 19, 2020 at 12:06 pm

    Please be specific on what you want the script to do.

    You want it to work only on video footage? Or maybe also on different layers?
    Only on the active composition or the entire project?
    And exactly like this one, treat them by the last 2 characters of the name?

    My Envato portfolio.

Viewing 1 - 2 of 2 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy