ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Enabling/Disabling Layers with Layer Name

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Addison Taylor
Enabling/Disabling Layers with Layer Name
on May 18, 2020 at 4:45:42 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" || layer.name.slice(-2) == selectedLanguage){layer.enabled = true};
else {layer.enabled = false};
if (layer.hasAudio && selectedLanguage == "All" || layer.name.slice(-2) == selectedLanguage){layer.audioEnabled = true};
else {layer.audioEnabled = false};
// For layers used both in EN & FR version
if (layer.name.slice(-5) == "EN/FR" && selectedLanguage == "EN" && layer.hasVideo){layer.enabled = true};
if (layer.name.slice(-5) == "EN/FR" && selectedLanguage == "EN" && layer.hasAudio){layer.audioEnabled = true};
if (layer.name.slice(-5) == "EN/FR" && selectedLanguage == "CH" && layer.hasVideo){layer.enabled = false};
if (layer.name.slice(-5) == "EN/FR" && selectedLanguage == "CH" && layer.hasAudio){layer.audioEnabled = false};
};
// Scan all layers
function goThroughLayers (Comp, selectedLanguage){
for (var p = 1; p &lt;= 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);
};
};
};


//UI
var w =new Window ("dialog","Select language");
w.orientation="column";
var radio_group = w.add ("panel");
radio_group.orientation="row";
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.orientation="row";
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(w.show ()== 1){
// Get selected language
for(var x = 0; x &lt; 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 &lt;= app.project.numItems; i++) {
if (app.project.item(i) instanceof CompItem) {
var Comp = app.project.item(i);
goThroughLayers(Comp, selectedLanguage);
}
}
app.endUndoGroup();
};


Return to posts index

Andrei Popa
Re: Enabling/Disabling Layers with Layer Name
on May 19, 2020 at 12:06:10 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?

Andrei
My Envato portfolio.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]